from docx import Document
from docx.enum.section import WD_ORIENT
from docx.shared import Mm
from docx.oxml.ns import qn
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.shared import Pt,RGBColor
from tkinter.simpledialog import askstring
from tkinter import StringVar
from tkinter import ttk
import tkinter as tk
import random
import sys
import os
import time
import re
import tkinter
import tkinter.messagebox
import getpass
import datetime
import Levenshtein
#import six 
#import packaging
#import packaging.version
#import packaging.specifiers
#import packaging.requirements

####预置全局变量###
gongneng_flag=0
count = 0#每次生成新题型之前都归零一次，用于遍历当前题库计算总题数
list_tihao=[]#随机从总题数里面抽一个输入数量的数组用于从题库抽题
new_tihao_tk=0#用于指定新题号来替代填空题库里的老题号
new_tihao_xz=0#用于指定新题号来替代选择题库里的老题号
new_tihao_pd=0#用于指定新题号来替代判断题库里的老题号
new_tihao_jd=0#用于指定新题号来替代简答题库里的老题号
ti = ''#用于将题读取出来再写入试卷
count_tishu_xz = 0#用于输入指定的选择题数
choose_count=0#用于指定大题类型
tiankong_ok = 0
xuanze_ok = 0
panduan_ok=0
jianda_ok = 0
homepage_flag = 0
####

init_text_str=''#全局字符串变量，用于题库初始化时告知用户题库是否存在
flag_SN_1 = 0 #第一大题生成标志，1为生成，0为为生成
flag_SN_2 = 0 #第二大题生成标志
flag_SN_3 = 0 #第三大题生成标志
flag_SN_4 = 0 #第四大题生成标志

def kill_progress():#退出程序
    print('退出程序')
    sys.exit(0)
def panduan_kong(ti_):#过滤掉空的回车键
    if  len(ti_)==0 :
        return False
    else :
        return True
def check_tk_tiku():#检查题库是否存在
    global init_text_str
    if os.path.exists(str(os.path.dirname(os.path.realpath(sys.argv[0]))) + '\\填空题题库.docx') == True:#获取当前软件程序所在文件夹中是否有填空题库文件
        init_text_str=('已检测到【填空题】题库文件，【填空题】题库存在')
        return 'tk_Y'
    else:
        init_text_str=('\n未检测到【填空题】题库文件，【填空题】题库不存在')
        return 'tk_N'
def check_xz_tiku():
    global init_text_str
    if os.path.exists(str(os.path.dirname(os.path.realpath(sys.argv[0]))) + '\\选择题题库.docx') == True:#获取当前软件程序所在文件夹中是否有选择题库文件
        init_text_str=('已检测到【选择题】题库文件，【选择题】题库存在')
        return 'xz_Y'
    else:
        init_text_str=('\n未检测到【选择题】题库文件，【选择题】题库不存在')
        return 'xz_N'
def check_pd_tiku():
    global init_text_str
    if os.path.exists(str(os.path.dirname(os.path.realpath(sys.argv[0]))) + '\\判断题题库.docx') == True:#获取当前软件程序所在文件夹中是否有选择题库文件
        init_text_str=('已检测到【判断题】题库文件，【判断题】题库存在')
        return 'pd_Y'
    else:
        init_text_str=('\n未检测到【判断题】题库文件，【判断题】题库不存在')
        return 'pd_N'       
def check_jd_tiku():
    global init_text_str
    if os.path.exists(str(os.path.dirname(os.path.realpath(sys.argv[0]))) + '\\简答题题库.docx') == True:#获取当前软件程序所在文件夹中是否有选择题库文件
        init_text_str=('已检测到【简答题】题库文件，【简答题】题库存在')
        return 'jd_Y'
    else:
        init_text_str=('\n未检测到【简答题】题库文件，【简答题】题库不存在')
        return 'jd_N'    
def dangerous_box_2(time):
    top = tkinter.Tk()
    top.withdraw()
    top.update()      
    tkinter.messagebox.showinfo('成功','试卷创建成功,文件为：\n'+time+'试题卷'+'\n'+time+'答案卷')
def dangerous_box(dangerous):#消息弹窗
    top = tkinter.Tk()
    top.withdraw()
    top.update()
    if dangerous ==1:
        tkinter.messagebox.showerror('错误','题库初始化失败，请根据提示检查【填空题题库】格式')
    if dangerous ==2:
        tkinter.messagebox.showerror('错误','题库初始化失败，请根据提示检查【选择题题库】格式')
    if dangerous ==3:
        tkinter.messagebox.showerror('错误','题库初始化失败，请根据提示检查【简答题题库】格式')
    if dangerous ==4:
        tkinter.messagebox.showinfo('成功','试卷创建成功')
    if dangerous ==5:
        tkinter.messagebox.showinfo('成功','题目添加成功')
    if dangerous ==6:
        tkinter.messagebox.showinfo('成功','题库创建成功')
    if dangerous ==7:
        tkinter.messagebox.showinfo('成功','题目删除成功')
    if dangerous ==8:
        tkinter.messagebox.showinfo('取消','已取消添加')
    if dangerous ==9:
        tkinter.messagebox.showerror('错误','题库初始化失败，请根据提示检查【判断题题库】格式')
    if dangerous ==10:
        tkinter.messagebox.showerror('错误','题干格式错误，请检查题干内是否缺少括号\n注意答案写在括号内')
    if dangerous ==11:
        tkinter.messagebox.showwarning('注意','未找到【填空题】题库')
    if dangerous ==12:
        tkinter.messagebox.showwarning('注意','未找到【选择题】题库')
    if dangerous ==13:
        tkinter.messagebox.showwarning('注意','未找到【判断题】题库')
    if dangerous ==14:
        tkinter.messagebox.showwarning('注意','未找到【简答题】题库')
    if dangerous ==15:
        tkinter.messagebox.showerror('错误','未抽取题目，试卷创建失败')
    if dangerous ==16:
        tkinter.messagebox.showwarning('注意','请按顺序出题')
    if dangerous ==17:
        tkinter.messagebox.showwarning('注意','请选择题型且按顺序出题')
    if dangerous ==18:
        tkinter.messagebox.showwarning('注意','软件编写匆忙\n避免不了仍有Bug\n请谅解')
    if dangerous ==19:
        tkinter.messagebox.showerror('错误','题库内题目格式错误\n请返回并初始化题库检查')
    if dangerous ==20:
        tkinter.messagebox.showerror('错误','请返回并初始化题库再重新创建试卷')
#############初始化页面######################
def init_progress():
    def dangerous_info():
        def previous_():#上一页
            dangerous_label_1.place(relx=0.5,rely=0.19,anchor='center')
            dangerous_label_1.config(text='*****************************\n① 题库文件名必须为：填空题题库、选择题题库、判断题题库、简答题题库\n② 题库为后缀名为docx的Word文档，各题内部禁止手动换行，换行符“┘”识别为题目结束\n③【填空题格式】：1、这是一个填空题，（答案）是括号里的。\n ！！注意填空题一定要有括号，且答案在括号当中\n④【选择题格式】：2、这是（A）选择题。&A、一个B、两个C、八个')
            dangerous_label_1.update()
            dangerous_label_2.place(relx=0.5,rely=0.61,anchor='center')
            dangerous_label_2.config(text='！！注意题干和选项之间用&符号隔开，同样，题干中必须要有答案在括号中\n！！注意在选择题中选项ABCD使用大写字母，选项内容中的ABCD使用小写字母\n！！注意在题目中仅可在答案处出现一个小括号，其他可用中括号代替\n⑤【判断题格式】：3、这个题是对的（√）\n！！注意题中必须有答案在括号中\n⑥【简答题格式】：4、这是一个简答题？&答案是我\n！！注意题干和答案之间用&符号隔开')
            dangerous_label_2.update()
        def next_():#下一页
            dangerous_label_1.place(relx=0.5,rely=0.19,anchor='center')
            dangerous_label_1.config(text='*****************************\n⑦ 概略清除重复题方法为判断每一题前八个字相同则视为重复题\n故无法精确识别重复题并清除，请务必定期审阅题库\n*****************************')
            dangerous_label_1.update()
            dangerous_label_2.place_forget()
        homepage_frame.place_forget()
        dangerous_frame.place(relx=0.15,rely=0.25,relwidth=0.7,relheight=0.65)
        previous_()
        dangerous_previous=tk.Button(dangerous_frame,text="上页",font=('黑体',13),command =previous_,bd=4)
        dangerous_next=tk.Button(dangerous_frame,text="下页",font=('黑体',13),command =next_,bd=4)
        dangerous_back=tk.Button(dangerous_frame,text="返回",font=('黑体',13),command =back_homepage,bd=4)
        dangerous_exit=tk.Button(dangerous_frame,text="退出",font=('黑体',13),command =kill_progress,bd=4)   
        dangerous_previous.place(relx=0.30,rely=0.90,anchor='center')
        dangerous_next.place(relx=0.43,rely=0.90,anchor='center')     
        dangerous_back.place(relx=0.56,rely=0.90,anchor='center')
        dangerous_exit.place(relx=0.69,rely=0.90,anchor='center')
    def homepage():
        print('进入首页')
        title_Warning.place(relx=0.5,rely=0.20,anchor='center')
        homepage_frame.place(relx=0.15,rely=0.25,relwidth=0.7,relheight=0.65)
        homepage_init=tk.Button(homepage_frame,text="初始化题库",font=('黑体',13),command =init_tiku,bd=4,width=9)
        homepage_menu=tk.Button(homepage_frame,text="创建管理",font=('黑体',13),command =menu,bd=4)
        homepage_dangerous=tk.Button(homepage_frame,text="帮助",font=('黑体',13),command =dangerous_info,bd=4)
        homepage_exit=tk.Button(homepage_frame,text="退出",font=('黑体',13),command =kill_progress,bd=4)
        homepage_init.place(relx=0.40,rely=0.30,anchor='center')
        homepage_menu.place(relx=0.61,rely=0.30,anchor='center')
        homepage_dangerous.place(relx=0.43,rely=0.50,anchor='center')
        homepage_exit.place(relx=0.56,rely=0.50,anchor='center')


    def init_tiku():#初始化题库
        print('进入题库初始化')
        title_Warning.place_forget()
        homepage_frame.place_forget()
        global init_text_str 
        init_Warning.place(relx=0.5,rely=0.20,anchor='center')
        init_frame.place(relx=0.15,rely=0.25,relwidth=0.7,relheight=0.65)
        init_label_tell.place(relx=0.5,rely=0.04,anchor='center')
        init_label_tk.place(relx=0.5,rely=0.15,anchor='center')
        init_label_xz.place(relx=0.5,rely=0.30,anchor='center')
        init_label_pd.place(relx=0.5,rely=0.45,anchor='center')
        init_label_jd.place(relx=0.5,rely=0.60,anchor='center')
        init_back.place(relx=0.43,rely=0.75,anchor='center')
        init_exit.place(relx=0.57,rely=0.75,anchor='center')
        init_label_tell.configure(text='正在扫描题库并初始化...')
        init_label_tell.update()
        flag_cuoti=0
        def remove_chongfu():
            if(check_tk_tiku()=='tk_N'):
                print('未找到【填空题】题库，请按规定格式创建题库或将题库和本程序放置于同一子文件夹下')
            else:
                ti=''
                list_chongfu_1=[]
                list_chongfu_2=[]
                list_chongfu_3=[]
                list_chongfu_3_1=[]
                list_chongfu_3_2=[]
                list_chongfu_4=[]
                count_chongfu=1
                tiankong_init = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\填空题题库.docx')
                for ti in tiankong_init.paragraphs:
                    if len(ti.text)!=0 :
                        list_chongfu_1.append(ti.text)
                for x in list_chongfu_1:
                        if x[0].isdigit()==True and x[1].isdigit()==False :
                                    new_ti_init=x.replace(x[0],str('n'),1)
                        if x[0].isdigit()==True and x[1].isdigit()==True and x[2].isdigit()==False:
                                    new_ti_init=x.replace(x[0]+x[1],str('n'),1)
                        if x[0].isdigit()==True and x[1].isdigit()==True and x[2].isdigit()==True:
                                    new_ti_init=x.replace(x[0]+x[1]+x[2],str('n'),1)
                        list_chongfu_2.append(''.join(new_ti_init.split()))
                        list_chongfu_3=set(list_chongfu_2)

                for ii in list_chongfu_3:
                    if ii[:8].replace(' ','') not in list_chongfu_3_1:
                        list_chongfu_3_2.append(ii)
                count_cf = 0
                list_cf_1=list_chongfu_3_2
                list_cf_2=[]
                list_cf_2_1=[]
                list_cf_3=[]
                list_cf_1=set(list_cf_1)#粗略去重
                for i in list_cf_1:
                    list_cf_2.append(i[:8])
                list_cf_2=set(list_cf_2)
                for x in list_cf_2:
                    list_cf_2_1.append(x)
                for ii in list_cf_1:
                    count_cf=0
                    for iii in list_cf_2_1:
                        if ii[:8]==iii:
                            list_cf_3.append(ii)
                            list_cf_2_1.pop(count_cf)
                        count_cf=count_cf+1                                   
                for y in list_cf_3:
                        if y[0]=='n' and y[1]!='n' and y[2]!='n':
                                    new_ti_init=y.replace(y[0],str(count_chongfu))
                        if y[0]=='n' and y[1]=='n' and y[2]!='n':
                                    new_ti_init=y.replace(x[0]+y[1],str(count_chongfu))
                        if y[0]=='n' and y[1]=='n' and y[2]=='n':
                                    new_ti_init=y.replace(y[0]+y[1]+y[2],str(count_chongfu))
                        list_chongfu_4.append(new_ti_init)
                        count_chongfu=count_chongfu+1
                count_chongfu=0
                chongfu_tiankong=Document()
                chongfu_tiankong.styles['Normal'].font.size = Pt(12)
                chongfu_tiankong.styles['Normal'].font.name = u'Times New Roman' #设置西文字体
                chongfu_tiankong.styles['Normal']._element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体') #设置中文字体使用字体2->宋体
                for chongfu_tk in list_chongfu_4:
                    new=chongfu_tiankong.add_paragraph(chongfu_tk)
                chongfu_tiankong.save(str(os.path.dirname(os.path.realpath(sys.argv[0]))) + '\\填空题题库.docx')   
                print('【填空题】题库重复题已经概略清除，如果要严格清除重复题，请手动打开题库文件并清除')
            
            if(check_xz_tiku()=='xz_N'):
                print('未找到【选择题】题库，请按规定格式创建题库或将题库和本程序放置于同一子文件夹下')
            else:
                ti=''
                list_chongfu_1=[]
                list_chongfu_2=[]
                list_chongfu_3=[]
                list_chongfu_3_1=[]
                list_chongfu_3_2=[]
                list_chongfu_4=[]
                count_chongfu=1
                xuanze_init = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\选择题题库.docx')
                for ti in xuanze_init.paragraphs:
                    if len(ti.text)!=0 :
                        list_chongfu_1.append(ti.text)
                for x in list_chongfu_1:
                        if x[0].isdigit()==True and x[1].isdigit()==False :
                                    new_ti_init=x.replace(x[0],str('n'),1)
                        if x[0].isdigit()==True and x[1].isdigit()==True and x[2].isdigit()==False:
                                    new_ti_init=x.replace(x[0]+x[1],str('n'),1)
                        if x[0].isdigit()==True and x[1].isdigit()==True and x[2].isdigit()==True:
                                    new_ti_init=x.replace(x[0]+x[1]+x[2],str('n'),1)
                
                        list_chongfu_2.append(''.join(new_ti_init.split()))
                        list_chongfu_3=set(list_chongfu_2)
                for ii in list_chongfu_3:
                    if ii[:8].replace(' ','') not in list_chongfu_3:
                        list_chongfu_3_2.append(ii)

                count_cf = 0
                list_cf_1=list_chongfu_3_2
                list_cf_2=[]
                list_cf_2_1=[]
                list_cf_3=[]
                list_cf_1=set(list_cf_1)#粗略去重
                for i in list_cf_1:
                    list_cf_2.append(i[:8])
                list_cf_2=set(list_cf_2)
                for x in list_cf_2:
                    list_cf_2_1.append(x)
                for ii in list_cf_1:
                    count_cf=0
                    for iii in list_cf_2_1:
                        if ii[:8]==iii:
                            list_cf_3.append(ii)
                            list_cf_2_1.pop(count_cf)
                        count_cf=count_cf+1                                   
                for y in list_cf_3:
                        if y[0]=='n' and y[1]!='n' and y[2]!='n':
                                    new_ti_init=y.replace(y[0],str(count_chongfu))
                        if y[0]=='n' and y[1]=='n' and y[2]!='n':
                                    new_ti_init=y.replace(x[0]+y[1],str(count_chongfu))
                        if y[0]=='n' and y[1]=='n' and y[2]=='n':
                                    new_ti_init=y.replace(y[0]+y[1]+y[2],str(count_chongfu))
                        list_chongfu_4.append(new_ti_init)
                        count_chongfu=count_chongfu+1
                #print(list_chongfu_4)
                count_chongfu=0
                chongfu_xuanze=Document()
                chongfu_xuanze.styles['Normal'].font.size = Pt(12)
                chongfu_xuanze.styles['Normal'].font.name = u'Times New Roman' #设置西文字体
                chongfu_xuanze.styles['Normal']._element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体') #设置中文字体使用字体2->宋体
                for chongfu_xz in list_chongfu_4:
                    if chongfu_xz.find('D')==-1:
                        new=chongfu_xuanze.add_paragraph(chongfu_xz.split('&')[0]+'&'+chongfu_xz.split('&')[1][:chongfu_xz.split('&')[1].find('B')]+'   '+chongfu_xz.split('&')[1][chongfu_xz.split('&')[1].find('B'):chongfu_xz.split('&')[1].find('C')]+'   '+chongfu_xz.split('&')[1][chongfu_xz.split('&')[1].find('C'):])
                    else :
                        new=chongfu_xuanze.add_paragraph(chongfu_xz.split('&')[0]+'&'+chongfu_xz.split('&')[1][:chongfu_xz.split('&')[1].find('B')]+'   '+chongfu_xz.split('&')[1][chongfu_xz.split('&')[1].find('B'):chongfu_xz.split('&')[1].find('C')]+'   '+chongfu_xz.split('&')[1][chongfu_xz.split('&')[1].find('C'):chongfu_xz.split('&')[1].find('D')]+'   '+chongfu_xz.split('&')[1][chongfu_xz.split('&')[1].find('D'):])
                chongfu_xuanze.save(str(os.path.dirname(os.path.realpath(sys.argv[0]))) + '\\选择题题库.docx')   
                print('【选择题】题库重复题已经概略清除，如果要严格清除重复题，请手动打开题库文件并清除')
            if(check_pd_tiku()=='pd_N'):
                print('未找到【判断题】题库，请按规定格式创建题库或将题库和本程序放置于同一子文件夹下')

            else:
                ti=''
                list_chongfu_1=[]
                list_chongfu_2=[]
                list_chongfu_3=[]
                list_chongfu_3_1=[]
                list_chongfu_3_2=[]
                list_chongfu_4=[]
                count_chongfu=1
                panduan_init = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\判断题题库.docx')
                for ti in panduan_init.paragraphs:
                    if len(ti.text)!=0 :
                        list_chongfu_1.append(ti.text)
                for x in list_chongfu_1:
                        if x[0].isdigit()==True and x[1].isdigit()==False :
                                    new_ti_init=x.replace(x[0],str('n'),1)
                        if x[0].isdigit()==True and x[1].isdigit()==True and x[2].isdigit()==False:
                                    new_ti_init=x.replace(x[0]+x[1],str('n'),1)
                        if x[0].isdigit()==True and x[1].isdigit()==True and x[2].isdigit()==True:
                                    new_ti_init=x.replace(x[0]+x[1]+x[2],str('n'),1)
                        list_chongfu_2.append(''.join(new_ti_init.split()))
                        list_chongfu_3=set(list_chongfu_2)
                for ii in list_chongfu_3:
                    if ii[:8].replace(' ','') not in list_chongfu_3_1:
                        list_chongfu_3_2.append(ii)
                count_cf = 0
                list_cf_1=list_chongfu_3_2
                list_cf_2=[]
                list_cf_2_1=[]
                list_cf_3=[]
                list_cf_1=set(list_cf_1)#粗略去重
                for i in list_cf_1:
                    list_cf_2.append(i[:8])
                list_cf_2=set(list_cf_2)
                for x in list_cf_2:
                    list_cf_2_1.append(x)
                for ii in list_cf_1:
                    count_cf=0
                    for iii in list_cf_2_1:
                        if ii[:8]==iii:
                            list_cf_3.append(ii)
                            list_cf_2_1.pop(count_cf)
                        count_cf=count_cf+1                                   
                for y in list_cf_3:
                        if y[0]=='n' and y[1]!='n' and y[2]!='n':
                                    new_ti_init=y.replace(y[0],str(count_chongfu))
                        if y[0]=='n' and y[1]=='n' and y[2]!='n':
                                    new_ti_init=y.replace(x[0]+y[1],str(count_chongfu))
                        if y[0]=='n' and y[1]=='n' and y[2]=='n':
                                    new_ti_init=y.replace(y[0]+y[1]+y[2],str(count_chongfu))
                        list_chongfu_4.append(new_ti_init)
                        count_chongfu=count_chongfu+1
                count_chongfu=0
                chongfu_panduan=Document()
                chongfu_panduan.styles['Normal'].font.size = Pt(12)
                chongfu_panduan.styles['Normal'].font.name = u'Times New Roman' #设置西文字体
                chongfu_panduan.styles['Normal']._element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体') #设置中文字体使用字体2->宋体
                for chongfu_pd in list_chongfu_4:
                    new=chongfu_panduan.add_paragraph(chongfu_pd)
                chongfu_panduan.save(str(os.path.dirname(os.path.realpath(sys.argv[0]))) + '\\判断题题库.docx')   
                print('【判断题】题库重复题已经概略清除，如果要严格清除重复题，请手动打开题库文件并清除')
            if(check_jd_tiku()=='jd_N'):
                print('未找到【简答题】题库，请按规定格式创建题库或将题库和本程序放置于同一子文件夹下')
            else:
                ti=''
                list_chongfu_1=[]
                list_chongfu_2=[]
                list_chongfu_3=[]
                list_chongfu_3_1=[]
                list_chongfu_3_2=[]
                list_chongfu_4=[]
                count_chongfu=1
                jianda_init = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\简答题题库.docx')
                for ti in jianda_init.paragraphs:
                    if len(ti.text)!=0 :
                        list_chongfu_1.append(ti.text)
                for x in list_chongfu_1:
                        if x[0].isdigit()==True and x[1].isdigit()==False :
                                    new_ti_init=x.replace(x[0],str('n'),1)
                        if x[0].isdigit()==True and x[1].isdigit()==True and x[2].isdigit()==False:
                                    new_ti_init=x.replace(x[0]+x[1],str('n'),1)
                        if x[0].isdigit()==True and x[1].isdigit()==True and x[2].isdigit()==True:
                                    new_ti_init=x.replace(x[0]+x[1]+x[2],str('n'),1)
                        list_chongfu_2.append(''.join(new_ti_init.split()))
                        list_chongfu_3=set(list_chongfu_2)
                for ii in list_chongfu_3:
                    if ii[:8].replace(' ','') not in list_chongfu_3_1:
                        list_chongfu_3_2.append(ii)
                count_cf = 0
                list_cf_1=list_chongfu_3_2
                list_cf_2=[]
                list_cf_2_1=[]
                list_cf_3=[]
                list_cf_1=set(list_cf_1)#粗略去重
                for i in list_cf_1:
                    list_cf_2.append(i[:8])
                list_cf_2=set(list_cf_2)
                for x in list_cf_2:
                    list_cf_2_1.append(x)
                for ii in list_cf_1:
                    count_cf=0
                    for iii in list_cf_2_1:
                        if ii[:8]==iii:
                            list_cf_3.append(ii)
                            list_cf_2_1.pop(count_cf)
                        count_cf=count_cf+1                                   
                for y in list_cf_3:
                        if y[0]=='n' and y[1]!='n' and y[2]!='n':
                                    new_ti_init=y.replace(y[0],str(count_chongfu))
                        if y[0]=='n' and y[1]=='n' and y[2]!='n':
                                    new_ti_init=y.replace(x[0]+y[1],str(count_chongfu))
                        if y[0]=='n' and y[1]=='n' and y[2]=='n':
                                    new_ti_init=y.replace(y[0]+y[1]+y[2],str(count_chongfu))
                        list_chongfu_4.append(new_ti_init)
                        count_chongfu=count_chongfu+1
                count_chongfu=0
                chongfu_jianda=Document()
                chongfu_jianda.styles['Normal'].font.size = Pt(12)
                chongfu_jianda.styles['Normal'].font.name = u'Times New Roman' #设置西文字体
                chongfu_jianda.styles['Normal']._element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体') #设置中文字体使用字体2->宋体
                for chongfu_jd in list_chongfu_4:
                    new=chongfu_jianda.add_paragraph(chongfu_jd)
                chongfu_jianda.save(str(os.path.dirname(os.path.realpath(sys.argv[0]))) + '\\简答题题库.docx')   
                print('【简答题】题库重复题已经概略清除，如果要严格清除重复题，请手动打开题库文件并清除')
            
            return
        if(check_tk_tiku()=='tk_N'):#初始化填空题题库
            init_label_tk.configure(text=init_text_str)
            init_label_tk.update()
            dangerous_box(11)
        else:
            init_label_tk.configure(text='已检测到【填空题】题库,正在对题库初始化...')
            init_label_tk.update()
            ti=''
            list_init_1=[]
            list_init_2=[]
            count_init=1
            count_init_cw=0
            list_init_cw_tk=[]
            new_ti_init=''
            cuoti=''       
            tiankong_init = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\填空题题库.docx')
            for ti in tiankong_init.paragraphs:
                if len(ti.text)!=0 :
                    list_init_1.append(ti.text)
            for x in list_init_1:
                    if x[0].isdigit()==False :
                                new_ti_init=str(count_init)+'、'+x
                    elif x[0].isdigit()==True  and x[1].isdigit()==True and x[2].isdigit()==True  and x[3]!='、' and x[3]!='.' :
                                new_ti_init=str(count_init)+'、'+x      
                    elif x[0].isdigit()==True and x[1].isdigit()==True and x[2].isdigit()==False and x[2]!='、' and x[2]!='.' :
                                new_ti_init=str(count_init)+'、'+x 
                    elif x[0].isdigit()==True and x[1].isdigit()==False and x[1]!='、' and x[1]!='.' :
                                new_ti_init=str(count_init)+'、'+x                                    
                    elif x[0].isdigit()==True and x[1].isdigit()==False :
                                new_ti_init=x.replace(x[0],str(count_init),1)
                    elif x[0].isdigit()==True and x[1].isdigit()==True and x[2].isdigit()==False:
                                new_ti_init=x.replace(x[0]+x[1],str(count_init),1)
                    elif x[0].isdigit()==True and x[1].isdigit()==True and x[2].isdigit()==True:
                                new_ti_init=x.replace(x[0]+x[1]+x[2],str(count_init),1)
                    list_init_2.append(new_ti_init)
                    count_init=count_init+1
            list_init_3=[]
            for x in list_init_2 :
                quanjiao_l=''#题库内半角括号统一转换为全角
                quanjiao_r=''
                quanjiao_l=x.replace('(','（')
                quanjiao_r=quanjiao_l.replace(')','）')
                if quanjiao_r[1]=='.':
                    list_init_3.append(quanjiao_r.replace('.','、',1))
                elif quanjiao_r[2]=='.':
                    list_init_3.append(quanjiao_r.replace('.','、',1))
                elif quanjiao_r[3]=='.':
                    list_init_3.append(quanjiao_r.replace('.','、',1))
                else:
                    list_init_3.append(quanjiao_r)
            count_init=0
            init_tiankong=Document()
            init_tiankong.styles['Normal'].font.size = Pt(12)
            init_tiankong.styles['Normal'].font.name = u'Times New Roman' #设置西文字体
            init_tiankong.styles['Normal']._element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体') #设置中文字体使用字体2->宋体
            for init_tk in list_init_3:
                new=init_tiankong.add_paragraph(init_tk)
            init_tiankong.save(str(os.path.dirname(os.path.realpath(sys.argv[0]))) + '\\填空题题库.docx')
            tiankongti = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\填空题题库.docx')
            for tiankong in tiankongti.paragraphs:#获取总共有多少题count
                if panduan_kong(tiankong.text)==True or len(tiankong.text.strip())!=0:
                    count_init_cw=count_init_cw+1
                    if tiankong.text.find('(')== -1 and tiankong.text.find('（')== -1 and tiankong.text.find(')')== -1 and tiankong.text.find('）')== -1:
                        list_init_cw_tk.append(count_init_cw)
                    elif (tiankong.text.count('(')== 0 and tiankong.text.count('（')== 0) or (tiankong.text.count(')')== 0 and tiankong.text.count('）')== 0):
                        list_init_cw_tk.append(count_init_cw)
                else:
                    count_init_cw = count_init_cw
            if(len(list_init_cw_tk)!=0):
                        dangerous_box(1)
                        for i in list_init_cw_tk:
                            cuoti=cuoti+'，'+str(i)      
                        flag_cuoti = 1                      
                        init_label_tk.configure(text='【填空题】题库中第'+cuoti[1:]+'题存在格式错误：【题干内缺少括号】')
                        init_label_tk.update()                      
            else:
                        init_label_tk.configure(text='【填空题】题库初始化成功，等待去重...')
                        init_label_tk.update()         
        if(check_xz_tiku()=='xz_N'):#初始化选择题题库
            init_label_xz.configure(text=init_text_str)
            init_label_xz.update()
            dangerous_box(12)
        else:
            init_label_xz.configure(text='已检测到【选择题】题库,正在对题库初始化...')
            init_label_xz.update()
            ti=''
            list_init_1=[]
            list_init_2=[]
            count_init=1
            count_init_cw=0
            list_init_cw_xz_dian=[]
            list_init_cw_xz_kuohao=[]
            list_init_cw_xz_ABCD=[]
            list_init_cw_xz_ch=[]
            new_ti_init=''
            cuoti_dian=''
            cuoti_kuohao=''
            cuoti_ABCD=''
            cuoti_ch=''
            xuanze_init = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\选择题题库.docx')
            for ti in xuanze_init.paragraphs:
                if len(ti.text)!=0 :
                    list_init_1.append(ti.text)
            for x in list_init_1:
                    if x[0].isdigit()==False :
                                new_ti_init=str(count_init)+'、'+x
                    elif x[0].isdigit()==True  and x[1].isdigit()==True and x[2].isdigit()==True  and x[3]!='、' and x[3]!='.' :
                                new_ti_init=str(count_init)+'、'+x      
                    elif x[0].isdigit()==True and x[1].isdigit()==True and x[2].isdigit()==False and x[2]!='、' and x[2]!='.' :
                                new_ti_init=str(count_init)+'、'+x 
                    elif x[0].isdigit()==True and x[1].isdigit()==False and x[1]!='、' and x[1]!='.' :
                                new_ti_init=str(count_init)+'、'+x                                    
                    elif x[0].isdigit()==True and x[1].isdigit()==False :
                                new_ti_init=x.replace(x[0],str(count_init),1)
                    elif x[0].isdigit()==True and x[1].isdigit()==True and x[2].isdigit()==False:
                                new_ti_init=x.replace(x[0]+x[1],str(count_init),1)
                    elif x[0].isdigit()==True and x[1].isdigit()==True and x[2].isdigit()==True:
                                new_ti_init=x.replace(x[0]+x[1]+x[2],str(count_init),1)
                    list_init_2.append(new_ti_init)
                    count_init=count_init+1
            list_init_3=[]
            for x in list_init_2 :
                quanjiao_l=''
                quanjiao_r=''
                quanjiao_l=x.replace('(','（')
                quanjiao_r=quanjiao_l.replace(')','）')
                if quanjiao_r[1]=='.':
                    list_init_3.append(quanjiao_r.replace('.','、',1))
                elif quanjiao_r[2]=='.':
                    list_init_3.append(quanjiao_r.replace('.','、',1))
                elif quanjiao_r[3]=='.':
                    list_init_3.append(quanjiao_r.replace('.','、',1))
                else:
                    list_init_3.append(quanjiao_r)         
            count_init=0
            init_xuanze=Document()
            init_xuanze.styles['Normal'].font.size = Pt(12)
            init_xuanze.styles['Normal'].font.name = u'Times New Roman' #设置西文字体
            init_xuanze.styles['Normal']._element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体') #设置中文字体使用字体2->宋体
            for init_xz in list_init_3:
                new=init_xuanze.add_paragraph(init_xz)
            init_xuanze.save(str(os.path.dirname(os.path.realpath(sys.argv[0]))) + '\\选择题题库.docx')    
            xuanzeti = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\选择题题库.docx')
            for xuanze in xuanzeti.paragraphs:#获取总共有多少题count
                if panduan_kong(xuanze.text)==True or len(xuanze.text.strip())!=0:
                    count_init_cw=count_init_cw+1
                    xuanze_xuanxiang=xuanze.text.split('&')
                    if xuanze.text.find('&')== -1 or xuanze.text.count('&')>1:
                        list_init_cw_xz_dian.append(count_init_cw)                  
                    elif xuanze.text.find('(')== -1 and xuanze.text.find('（')== -1 and xuanze.text.find(')')== -1 and xuanze.text.find('）')== -1:
                        list_init_cw_xz_kuohao.append(count_init_cw)
                    elif (xuanze.text.count('(')== 0 and xuanze.text.count('（')== 0) or (xuanze.text.count(')')== 0 and xuanze.text.count('）')== 0):
                        list_init_cw_xz_kuohao.append(count_init_cw)
                    elif (xuanze.text.count('（')>1 or xuanze.text.count('）')>1):
                        list_init_cw_xz_ch.append(count_init_cw)
                    else:
                        xuanze_xuanxiang=xuanze.text.split('&')
                        if xuanze_xuanxiang[1].count('A')>1 or xuanze_xuanxiang[1].count('B')>1 or xuanze_xuanxiang[1].count('C')>1 or xuanze_xuanxiang[1].count('D')>1:
                            list_init_cw_xz_ABCD.append(count_init_cw)
                else:
                    count_init_cw = count_init_cw
            if (len(list_init_cw_xz_dian)!=0):
                        dangerous_box(2)
                        for i in list_init_cw_xz_dian:
                            cuoti_dian=cuoti_dian+','+str(i)
                        flag_cuoti = 1 
                        init_label_xz.configure(text='【选择题】题库中第'+cuoti_dian[1:]+'题存在格式错误：【题干与选项之间缺少符号“&”隔开 】\n或【&符号位置或数量不正确，每题中仅可有一个&】')
                        init_label_xz.update()     
            elif (len(list_init_cw_xz_kuohao)!=0):
                        dangerous_box(2)
                        for i in list_init_cw_xz_kuohao:
                            cuoti_kuohao=cuoti_kuohao+','+str(i)
                        flag_cuoti = 1 
                        init_label_xz.configure(text='【选择题】题库中第'+cuoti_kuohao[1:]+'题存在格式错误：【题干内缺少括号】')
                        init_label_xz.update()    
            elif (len(list_init_cw_xz_ABCD)!=0):
                        dangerous_box(2)
                        for i in list_init_cw_xz_ABCD:
                            cuoti_ABCD=cuoti_ABCD+','+str(i)
                        flag_cuoti = 1 
                        init_label_xz.configure(text='【选择题】题库中第'+cuoti_ABCD[1:]+'题存在格式错误：【选项内容中出现多个大写ABCD】,可改用小写字母')
                        init_label_xz.update()    
            elif(len(list_init_cw_xz_ch)!=0):
                        dangerous_box(2)
                        for i in list_init_cw_xz_ch:
                            cuoti_ch=cuoti_ch+','+str(i)
                        flag_cuoti = 1 
                        init_label_xz.configure(text='【选择题】题库中第'+cuoti_ch[1:]+'题存在格式错误：【选择题中出现多个小括号】,非答案部分可改用中括号')
                        init_label_xz.update()                          
            else:     
                init_label_xz.configure(text='【选择题】题库初始化成功，等待去重...')
                init_label_xz.update()      
        if(check_pd_tiku()=='pd_N'):#初始化判断题题库
            init_label_pd.configure(text=init_text_str)
            init_label_pd.update()
            dangerous_box(13)
        else:
            init_label_pd.configure(text='已检测到【判断题】题库,正在对题库初始化...')
            init_label_pd.update()
            ti=''
            list_init_1=[]
            list_init_2=[]
            count_init=1
            count_init_cw=0
            list_init_cw_pd=[]
            new_ti_init=''
            cuoti=''
            panduan_init = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\判断题题库.docx')
            for ti in panduan_init.paragraphs:
                if len(ti.text)!=0 :
                    list_init_1.append(ti.text)

            for x in list_init_1:
                    if x[0].isdigit()==False :
                                new_ti_init=str(count_init)+'、'+x
                    elif x[0].isdigit()==True  and x[1].isdigit()==True and x[2].isdigit()==True  and x[3]!='、' and x[3]!='.' :
                                new_ti_init=str(count_init)+'、'+x      
                    elif x[0].isdigit()==True and x[1].isdigit()==True and x[2].isdigit()==False and x[2]!='、' and x[2]!='.' :
                                new_ti_init=str(count_init)+'、'+x 
                    elif x[0].isdigit()==True and x[1].isdigit()==False and x[1]!='、' and x[1]!='.' :
                                new_ti_init=str(count_init)+'、'+x                                    
                    elif x[0].isdigit()==True and x[1].isdigit()==False :
                                new_ti_init=x.replace(x[0],str(count_init),1)
                    elif x[0].isdigit()==True and x[1].isdigit()==True and x[2].isdigit()==False:
                                new_ti_init=x.replace(x[0]+x[1],str(count_init),1)
                    elif x[0].isdigit()==True and x[1].isdigit()==True and x[2].isdigit()==True:
                                new_ti_init=x.replace(x[0]+x[1]+x[2],str(count_init),1)
                    list_init_2.append(new_ti_init)
                    count_init=count_init+1
            list_init_3=[]
            for x in list_init_2 :
                quanjiao_l=''
                quanjiao_r=''
                quanjiao_l=x.replace('(','（')
                quanjiao_r=quanjiao_l.replace(')','）')
                if quanjiao_r[1]=='.':
                    list_init_3.append(quanjiao_r.replace('.','、',1))
                elif quanjiao_r[2]=='.':
                    list_init_3.append(quanjiao_r.replace('.','、',1))
                elif quanjiao_r[3]=='.':
                    list_init_3.append(quanjiao_r.replace('.','、',1))
                else:
                    list_init_3.append(quanjiao_r)
            count_init=0
            init_panduan=Document()
            init_panduan.styles['Normal'].font.size = Pt(12)
            init_panduan.styles['Normal'].font.name = u'Times New Roman' #设置西文字体
            init_panduan.styles['Normal']._element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体') #设置中文字体使用字体2->宋体
            for init_pd in list_init_3:
                new=init_panduan.add_paragraph(init_pd)
            init_panduan.save(str(os.path.dirname(os.path.realpath(sys.argv[0]))) + '\\判断题题库.docx')   
            panduanti = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\判断题题库.docx')
            for panduan in panduanti.paragraphs:#获取总共有多少题count
                if panduan_kong(panduan.text)==True or len(panduan.text.strip())!=0:
                    count_init_cw=count_init_cw+1
                    if panduan.text.find('(')== -1 and panduan.text.find('（')== -1 and panduan.text.find(')')== -1 and panduan.text.find('）')== -1:
                        list_init_cw_pd.append(count_init_cw)
                    elif (panduan.text.count('(')== 0 and panduan.text.count('（')== 0) or (panduan.text.count(')')== 0 and panduan.text.count('）')== 0):
                        list_init_cw_pd.append(count_init_cw)
                else:
                    count_init_cw = count_init_cw
            if(len(list_init_cw_pd)!=0):
                        dangerous_box(9)
                        for i in list_init_cw_pd :
                            cuoti=cuoti+','+str(i)
                        flag_cuoti = 1 
                        init_label_pd.configure(text='【判断题】题库中第'+cuoti[1:]+'题存在格式错误：【题干内缺少括号】')
                        init_label_pd.update()   
            else:                  
                init_label_pd.configure(text='【判断题】题库初始化成功，等待去重...')
                init_label_pd.update()          
        if(check_jd_tiku()=='jd_N'):#初始化简答题题库
            init_label_jd.configure(text=init_text_str)
            init_label_jd.update()
            dangerous_box(14)
        else:
            init_label_jd.configure(text='已检测到【简答题】题库,正在对题库初始化...')
            init_label_jd.update()
            ti=''
            list_init_1=[]
            list_init_2=[]
            count_init=1
            count_init_cw=0
            list_init_cw_jd=[]
            new_ti_init=''
            cuoti=''      
            jianda_init = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\简答题题库.docx')
            for ti in jianda_init.paragraphs:
                if len(ti.text)!=0 :
                    list_init_1.append(ti.text)
            for x in list_init_1:
                    if x[0].isdigit()==False :
                                new_ti_init=str(count_init)+'、'+x
                    elif x[0].isdigit()==True  and x[1].isdigit()==True and x[2].isdigit()==True  and x[3]!='、' and x[3]!='.' :
                                new_ti_init=str(count_init)+'、'+x      
                    elif x[0].isdigit()==True and x[1].isdigit()==True and x[2].isdigit()==False and x[2]!='、' and x[2]!='.' :
                                new_ti_init=str(count_init)+'、'+x 
                    elif x[0].isdigit()==True and x[1].isdigit()==False and x[1]!='、' and x[1]!='.' :
                                new_ti_init=str(count_init)+'、'+x                                    
                    elif x[0].isdigit()==True and x[1].isdigit()==False :
                                new_ti_init=x.replace(x[0],str(count_init),1)
                    elif x[0].isdigit()==True and x[1].isdigit()==True and x[2].isdigit()==False:
                                new_ti_init=x.replace(x[0]+x[1],str(count_init),1)
                    elif x[0].isdigit()==True and x[1].isdigit()==True and x[2].isdigit()==True:
                                new_ti_init=x.replace(x[0]+x[1]+x[2],str(count_init),1)
                    list_init_2.append(new_ti_init)
                    count_init=count_init+1
            list_init_3=[]
            for x in list_init_2 :
                quanjiao_l=''
                quanjiao_r=''
                quanjiao_l=x.replace('(','（')
                quanjiao_r=quanjiao_l.replace(')','）')
                if quanjiao_r[1]=='.':
                    list_init_3.append(quanjiao_r.replace('.','、',1))
                elif quanjiao_r[2]=='.':
                    list_init_3.append(quanjiao_r.replace('.','、',1))
                elif quanjiao_r[3]=='.':
                    list_init_3.append(quanjiao_r.replace('.','、',1))
                else:
                    list_init_3.append(quanjiao_r)          
            count_init=0
            init_jianda=Document()
            init_jianda.styles['Normal'].font.size = Pt(12)
            init_jianda.styles['Normal'].font.name = u'Times New Roman' #设置西文字体
            init_jianda.styles['Normal']._element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体') #设置中文字体使用字体2->宋体
            for init_jd in list_init_3:
                new=init_jianda.add_paragraph(init_jd)
            init_jianda.save(str(os.path.dirname(os.path.realpath(sys.argv[0]))) + '\\简答题题库.docx')   
            jiandati = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\简答题题库.docx')
            for jianda in jiandati.paragraphs:#获取总共有多少题cunt
                if panduan_kong(jianda.text)==True or len(jianda.text.strip())!=0:
                    count_init_cw=count_init_cw+1
                    if jianda.text.find('&')== -1 or jianda.text.count('&')>1:
                        list_init_cw_jd.append(count_init_cw)
                else:
                    count_init_cw = count_init_cw
            if(len(list_init_cw_jd)!=0):
                        dangerous_box(3)
                        for i in list_init_cw_jd :
                            cuoti=cuoti+'-'+str(i)
                        flag_cuoti = 1 
                        init_label_jd.configure(text='【简答题】题库中第'+cuoti+'题存在格式错误：【题干与答案之间缺少符号“&” 隔开】\n或【&符号位置或数量不正确，每题中仅可有一个&】')
                        init_label_jd.update()   
            else:      
                init_label_jd.configure(text='【简答题】题库初始化成功，等待去重...')
                init_label_jd.update()          
        if check_tk_tiku()=='tk_N' and check_xz_tiku()=='xz_N' and check_pd_tiku()=='pd_N' and check_jd_tiku()=='jd_N':
            init_label_tell.configure(text='没有找到任何题库文件')
            init_label_tell.update()  
        elif flag_cuoti == 1 :
            init_label_tell.configure(text='题库初始化失败，请检查题库内容格式...')
            init_label_tell.update()
        else:
            init_label_tell.configure(text='题库初始化完成...')
            init_label_tell.update()
        ##################################################################################
        
        if len(list_init_cw_tk)==0 and len(list_init_cw_pd)==0 and len(list_init_cw_jd)==0 and len(list_init_cw_xz_dian)==0 and len(list_init_cw_xz_kuohao)==0 and len(list_init_cw_xz_ABCD)==0 and len(list_init_cw_xz_ch)==0:
            remove_chongfu()
            init_label_tk.configure(text='【填空题】题库初始化成功，重复题已概略清除')
            init_label_tk.update()    
            init_label_xz.configure(text='【选择题】题库初始化成功，重复题已概略清除')
            init_label_xz.update() 
            init_label_pd.configure(text='【判断题】题库初始化成功，重复题已概略清除')
            init_label_pd.update() 
            init_label_jd.configure(text='【简答题】题库初始化成功，重复题已概略清除')
            init_label_jd.update() 
        else:
            if len(list_init_cw_tk)!=0 and len(list_init_cw_pd)==0 and len(list_init_cw_jd)==0 and len(list_init_cw_xz_dian)==0 and len(list_init_cw_xz_kuohao)==0 and len(list_init_cw_xz_ABCD)==0 and len(list_init_cw_xz_ch)==0:  
                init_label_xz.configure(text='【选择题】题库初始化失败')
                init_label_xz.update() 
                init_label_pd.configure(text='【判断题】题库初始化失败')
                init_label_pd.update() 
                init_label_jd.configure(text='【简答题】题库初始化失败')
                init_label_jd.update() 
            if len(list_init_cw_tk)==0 and len(list_init_cw_pd)!=0 and len(list_init_cw_jd)==0 and len(list_init_cw_xz_dian)==0 and len(list_init_cw_xz_kuohao)==0 and len(list_init_cw_xz_ABCD)==0 and len(list_init_cw_xz_ch)==0:  
                init_label_tk.configure(text='【填空题】题库初始化失败')
                init_label_tk.update()    
                init_label_xz.configure(text='【选择题】题库初始化失败')
                init_label_xz.update() 
                init_label_jd.configure(text='【简答题】题库初始化失败')
                init_label_jd.update() 
            if len(list_init_cw_tk)==0 and len(list_init_cw_pd)==0 and len(list_init_cw_jd)!=0 and len(list_init_cw_xz_dian)==0 and len(list_init_cw_xz_kuohao)==0 and len(list_init_cw_xz_ABCD)==0 and len(list_init_cw_xz_ch)==0:  
                init_label_tk.configure(text='【填空题】题库初始化失败')
                init_label_tk.update()    
                init_label_xz.configure(text='【选择题】题库初始化失败')
                init_label_xz.update() 
                init_label_pd.configure(text='【判断题】题库初始化失败')
                init_label_pd.update() 
            if len(list_init_cw_tk)==0 and len(list_init_cw_pd)==0 and len(list_init_cw_jd)==0 and len(list_init_cw_xz_dian)!=0 or len(list_init_cw_xz_kuohao)!=0 or len(list_init_cw_xz_ABCD)!=0 or len(list_init_cw_xz_ch)!=0:  
                init_label_tk.configure(text='【填空题】题库初始化失败')
                init_label_tk.update()    
                init_label_pd.configure(text='【判断题】题库初始化失败')
                init_label_pd.update() 
                init_label_jd.configure(text='【简答题】题库初始化失败')
                init_label_jd.update() 
            print('题库内存在错误，无法去重')

#############返回主菜单##############
    def back_homepage():#返回主菜单
        global flag_SN_1 , flag_SN_2 , flag_SN_3 , flag_SN_4#用于判断是否有选择题目抽取入试卷
        flag_SN_1=0 
        flag_SN_2=0 
        flag_SN_3=0 
        flag_SN_4=0
        global new_tihao_tk ,new_tihao_xz , new_tihao_pd , new_tihao_jd
        new_tihao_tk=0
        new_tihao_xz=0
        new_tihao_pd=0
        new_tihao_jd=0
        dangerous_frame.place_forget()
        init_frame.place_forget()#此容器遗忘后会将容器内部的控件均遗忘
        init_Warning.place_forget() 
        options_frame.place_forget()
        paper_info.place_forget()
        paper_frame.place_forget()
        choose_frame.place_forget()#此容器遗忘后会将容器内部的控件均遗忘
        manage_frame.place_forget()
        homepage()       
            
    ############主菜单############################
    def creat_paper():#创建试卷
        print('进入创建试卷')
        options_frame.place_forget()
        paper_info_init='请选择试卷参数'
        paper_info.place(relx=0.5,rely=0.20,anchor='center')
        paper_info.configure(text=paper_info_init)
        paper_info.update() 
        paper_frame.place(relx=0.15,rely=0.25,relwidth=0.7,relheight=0.65)
        paper_label.place(relx=0.50,rely=0.15,anchor='center')
        paper_label.config(text='请选择纸张大小')
        paper_label.update()
        paper_A3.place(relx=0.41,rely=0.30,anchor='center')
        paper_A4.place(relx=0.59,rely=0.30,anchor='center')
        paper_back.place(relx=0.43,rely=0.50,anchor='center')
        paper_exit.place(relx=0.56,rely=0.50,anchor='center')
        paper_name.place_forget()
        paper_name_2.place_forget()
        paper_enter.place_forget()
        paper_landscape.place_forget()
        paper_lengthways.place_forget()
    paper_info_A3A4=['纸张大小【A3】','纸张大小【A4】']
    paper_info_direction=['纸张方向【横向】','纸张方向【纵向】']
    paper_info_name='试卷标题为：'
    flag_A3A4=0#选择纸张大小为A3或者A4的标志，1为A3，2为A4
    flag_direction=0#选择纸张方向的标志，1为横向，2为纵向
    def A3():
        global flag_A3A4
        print('选择A3纸张')
        paper_A3.place_forget()
        paper_A4.place_forget()
        paper_info.configure(text=paper_info_A3A4[0])
        paper_info.update()    
        flag_A3A4=1
        paper_label.config(text='请选择纸张方向')
        paper_label.update()
        paper_landscape.place(relx=0.43,rely=0.30,anchor='center')
        paper_lengthways.place(relx=0.56,rely=0.30,anchor='center')          
    def A4():
        global flag_A3A4
        print('选择A4纸张')
        paper_A3.place_forget()
        paper_A4.place_forget()
        paper_info.configure(text=paper_info_A3A4[1])
        paper_info.update() 
        flag_A3A4=2
        paper_label.config(text='请选择纸张方向')
        paper_label.update()
        paper_landscape.place(relx=0.43,rely=0.30,anchor='center')
        paper_lengthways.place(relx=0.56,rely=0.30,anchor='center')
    def landscape():#选择横向
        global flag_A3A4,flag_direction
        print('选择横向')
        paper_landscape.place_forget()
        paper_lengthways.place_forget()
        if flag_A3A4==1:
            paper_info.configure(text=paper_info_A3A4[0]+paper_info_direction[0])
            paper_info.update() 
        elif flag_A3A4==2:
            paper_info.configure(text=paper_info_A3A4[1]+paper_info_direction[0])
            paper_info.update() 
        flag_direction=1
        paper_name_input()
    def lengthways():#选择纵向
        global flag_A3A4,flag_direction
        print('选择纵向')
        paper_landscape.place_forget()
        paper_lengthways.place_forget()
        if flag_A3A4==1:
            paper_info.configure(text=paper_info_A3A4[0]+paper_info_direction[1])
            paper_info.update() 
        elif flag_A3A4==2:
            paper_info.configure(text=paper_info_A3A4[1]+paper_info_direction[1])
            paper_info.update() 
        flag_direction=2
        paper_name_input()
    def paper_name_input():
        print('输入试卷名称')
        paper_label.config(text='请输入试卷标题')
        paper_label.update()
        paper_name.place(relx=0.5,rely=0.25,anchor='center')
        paper_name_2.place(relx=0.5,rely=0.35,anchor='center')
        enter_default.set(r'在此输入试卷标题')
        enter_default_2.set(r'副标题（可省略）')
        paper_enter.place(relx=0.75,rely=0.30,anchor='center')
    def enter_name():
        global flag_A3A4,flag_direction
        print('确认名称')
        if len(paper_name.get())==0:
            print('请输入试卷标题')
            enter_default.set(r'在此输入试卷标题')
        else:
            if flag_A3A4==1 and flag_direction==1:
                #print(paper_info_A3A4[0]+paper_info_direction[0]+paper_info_name+str(paper_name.get().strip()))
                if str(paper_name_2.get().strip())=='副标题（可省略）' or len(str(paper_name_2.get().strip()))==0:
                    paper_info.configure(text=paper_info_A3A4[0]+paper_info_direction[0]+paper_info_name+'-'+str(paper_name.get().strip())+'-')
                else:
                    paper_info.configure(text=paper_info_A3A4[0]+paper_info_direction[0]+paper_info_name+'-'+str(paper_name.get().strip())+'-'+'('+str(paper_name_2.get().strip())+')')
                paper_info.update() 
            elif flag_A3A4==1 and flag_direction==2:
                #print(paper_info_A3A4[0]+paper_info_direction[1]+paper_info_name+str(paper_name.get().strip()))
                if str(paper_name_2.get().strip())=='副标题（可省略）' or len(str(paper_name_2.get().strip()))==0:
                    paper_info.configure(text=paper_info_A3A4[0]+paper_info_direction[0]+paper_info_name+'-'+str(paper_name.get().strip())+'-')
                else:
                    paper_info.configure(text=paper_info_A3A4[0]+paper_info_direction[0]+paper_info_name+'-'+str(paper_name.get().strip())+'-'+'('+str(paper_name_2.get().strip())+')')
                paper_info.update()
            if flag_A3A4==2 and flag_direction==1:
                #print(paper_info_A3A4[1]+paper_info_direction[0]+paper_info_name+str(paper_name.get().strip()))
                if str(paper_name_2.get().strip())=='副标题（可省略）' or len(str(paper_name_2.get().strip()))==0:
                    paper_info.configure(text=paper_info_A3A4[0]+paper_info_direction[0]+paper_info_name+'-'+str(paper_name.get().strip())+'-')
                else:
                    paper_info.configure(text=paper_info_A3A4[0]+paper_info_direction[0]+paper_info_name+'-'+str(paper_name.get().strip())+'-'+'('+str(paper_name_2.get().strip())+')')
                paper_info.update()  
            if flag_A3A4==2 and flag_direction==2:
                #print(paper_info_A3A4[1]+paper_info_direction[1]+paper_info_name+str(paper_name.get().strip()))
                if str(paper_name_2.get().strip())=='副标题（可省略）' or len(str(paper_name_2.get().strip()))==0:
                    paper_info.configure(text=paper_info_A3A4[0]+paper_info_direction[0]+paper_info_name+'-'+str(paper_name.get().strip())+'-')
                else:
                    paper_info.configure(text=paper_info_A3A4[0]+paper_info_direction[0]+paper_info_name+'-'+str(paper_name.get().strip())+'-'+'('+str(paper_name_2.get().strip())+')')
                paper_info.update() 
            choose_type()
    def choose_type():
        global flag_A3A4,flag_direction
        print('试卷题型参数选择')
        def creat_star():
            if flag_SN_1!=0 : #第一大题已经抽取则可以生成试卷
                choose_enter.config(state='normal',fg='black')
            else:
                choose_1_info_5.config(fg='lightslategray')
                choose_2_info_5.config(fg='lightslategray')
                choose_3_info_5.config(fg='lightslategray')
                choose_4_info_5.config(fg='lightslategray')
                choose_1_info_4.config(state='disabled')
                choose_2_info_4.config(state='disabled')
                choose_3_info_4.config(state='disabled')
                choose_4_info_4.config(state='disabled')
                choose_1_info_3.config(state='normal')
                choose_1_info_3.delete(0,'end')
                choose_1_info_3.config(state='disabled')
                choose_2_info_3.config(state='normal')
                choose_2_info_3.delete(0,'end')
                choose_2_info_3.config(state='disabled')
                choose_3_info_3.config(state='normal')
                choose_3_info_3.delete(0,'end')
                choose_3_info_3.config(state='disabled')
                choose_4_info_3.config(state='normal') 
                choose_4_info_3.delete(0,'end')
                choose_4_info_3.config(state='disabled')    
                choose_enter.config(state='disabled',fg='red')
            def select_paper():#对Word试卷页面进行设置
                print('试卷纸张大小为：'+paper_info_A3A4[flag_A3A4-1]+'试卷方向为：'+paper_info_direction[flag_direction-1]+paper_info_name+str(paper_name.get().strip()))           
                shijuan = Document()     
                shijuan.styles['Normal'].font.name = '仿宋'#以下两句设置正文字体
                shijuan.styles['Normal']._element.rPr.rFonts.set(qn('w:eastAsia'),'仿宋')#设置代码为东亚，一般跟着上面一句
                dajuan = Document()
                dajuan.styles['Normal'].font.name = '仿宋'#以下两句设置正文字体
                dajuan.styles['Normal']._element.rPr.rFonts.set(qn('w:eastAsia'),'仿宋')#设置代码为东亚，一般跟着上面一句
                section = shijuan.sections[0]
                section_dajuan = dajuan.sections[0]
                if flag_A3A4 ==1 : #A3纸张
                    section.page_height = Mm(420)#以下两句是设置纸张大小为A4
                    section.page_width = Mm(297) 
                    section_dajuan.page_height = Mm(420)#以下两句是设置纸张大小为A4
                    section_dajuan.page_width = Mm(297) 
                elif flag_A3A4==2: #A4纸张
                    section.page_height = Mm(297)#以下两句是设置纸张大小为A4
                    section.page_width = Mm(210) 
                    section_dajuan.page_height = Mm(297)#以下两句是设置纸张大小为A4
                    section_dajuan.page_width = Mm(210) 
                if flag_direction ==1 : #横向
                    new_width,new_height = section.page_height,section.page_width#以下四局是设置纸张方向为横向
                    section.orientation = WD_ORIENT.LANDSCAPE
                    section.page_width = new_width
                    section.page_height = new_height
                    ############设置试卷标题头##########
                    biaoti=shijuan.add_heading('',level = 0)#添加一个标题
                    if str(paper_name_2.get().strip())=='副标题（可省略）' or len(str(paper_name_2.get().strip()))==0:
                        biaotiwz  = biaoti.add_run(str(paper_name.get().strip()))#添加标题的内容
                        biaotiwz.font.name='黑体'#以下两句为专门改变标题字体和颜色的语法
                        biaotiwz._element.rPr.rFonts.set(qn('w:eastAsia'), '黑体')
                        biaotiwz.font.color.rgb = RGBColor(0,0,0)#改变字体颜色
                        biaoti.alignment = WD_ALIGN_PARAGRAPH.CENTER#设置标题（段落）居中
                    else:
                        biaotiwz  = biaoti.add_run(str(paper_name.get().strip()))#添加标题的内容
                        biaotiwz.font.name='黑体'#以下两句为专门改变标题字体和颜色的语法
                        biaotiwz._element.rPr.rFonts.set(qn('w:eastAsia'), '黑体')
                        biaotiwz.font.color.rgb = RGBColor(0,0,0)#改变字体颜色
                        biaotiwz2 = biaoti.add_run('('+str(paper_name_2.get().strip())+')')
                        biaotiwz2.font.name='黑体'#以下两句为专门改变标题字体和颜色的语法
                        biaotiwz2._element.rPr.rFonts.set(qn('w:eastAsia'), '楷体')
                        biaotiwz2.font.color.rgb = RGBColor(0,0,0)#改变字体颜色     
                        biaotiwz2.font.size = Pt(15) 
                        biaoti.alignment = WD_ALIGN_PARAGRAPH.CENTER#设置标题（段落）居中                  
                    biaoti2=shijuan.add_heading('',level=3)
                    biaoti2xm = biaoti2.add_run("")
                    biaoti2xm.text='单位                  姓名                    分数'
                    biaoti2xm.font.name='楷体'#以下两句为专门改变标题字体和颜色的语法
                    biaoti2xm._element.rPr.rFonts.set(qn('w:eastAsia'), '楷体')
                    section._sectPr.xpath('./w:cols')[0].set(qn('w:num'),'2')#将试卷分两栏
                    new_width,new_height = section_dajuan.page_height,section_dajuan.page_width#以下四局是设置纸张方向为纵向
                    section_dajuan.orientation = WD_ORIENT.LANDSCAPE
                    section_dajuan.page_width = new_width
                    section_dajuan.page_height = new_height
            #####################设置答卷标题头##########
                    biaoti_dajuan=dajuan.add_heading('',level = 0)#添加一个标题
                    if str(paper_name_2.get().strip())=='副标题（可省略）' or len(str(paper_name_2.get().strip()))==0:
                        biaotiwz_dajuan  = biaoti_dajuan.add_run(str(paper_name.get().strip())+'('+'答案'+')')#添加标题的内容
                        biaotiwz_dajuan.font.name='黑体'#以下两句为专门改变标题字体和颜色的语法
                        biaotiwz_dajuan._element.rPr.rFonts.set(qn('w:eastAsia'), '黑体')
                        biaotiwz_dajuan.font.color.rgb = RGBColor(0,0,0)#改变字体颜色
                        biaoti_dajuan.alignment = WD_ALIGN_PARAGRAPH.CENTER#设置标题（段落）居中
                    else:
                        biaotiwz_dajuan  = biaoti_dajuan.add_run(str(paper_name.get().strip()))#添加标题的内容
                        biaotiwz_dajuan.font.name='黑体'#以下两句为专门改变标题字体和颜色的语法
                        biaotiwz_dajuan._element.rPr.rFonts.set(qn('w:eastAsia'), '黑体')
                        biaotiwz_dajuan.font.color.rgb = RGBColor(0,0,0)#改变字体颜色
                        biaotiwz_dajuan2 = biaoti_dajuan.add_run('('+str(paper_name_2.get().strip())+')'+'('+'答案'+')')
                        biaotiwz_dajuan2.font.name='黑体'#以下两句为专门改变标题字体和颜色的语法
                        biaotiwz_dajuan2._element.rPr.rFonts.set(qn('w:eastAsia'), '楷体')
                        biaotiwz_dajuan2.font.color.rgb = RGBColor(0,0,0)#改变字体颜色     
                        biaotiwz_dajuan2.font.size = Pt(15) 
                        biaoti_dajuan.alignment = WD_ALIGN_PARAGRAPH.CENTER#设置标题（段落）居中     
                    biaoti2_dajuan=dajuan.add_heading('',level=3)
                    biaoti2xm_dajuan = biaoti2_dajuan.add_run("")
                    biaoti2xm_dajuan.text='单位                  姓名                    分数'
                    biaoti2xm_dajuan.font.name='楷体'#以下两句为专门改变标题字体和颜色的语法
                    biaoti2xm_dajuan._element.rPr.rFonts.set(qn('w:eastAsia'), '楷体')
                    section_dajuan._sectPr.xpath('./w:cols')[0].set(qn('w:num'),'2')#将试卷分两栏
                elif flag_direction ==2: #纵向
                    new_width,new_height = section.page_width,section.page_height#以下四句是设置纸张方向为横向
                    section.orientation = WD_ORIENT.PORTRAIT
                    section.page_width = new_width
                    section.page_height = new_height
                            ########设置试卷标题头##########
                    biaoti=shijuan.add_heading('',level = 0)#添加一个标题
                    if str(paper_name_2.get().strip())=='副标题（可省略）' or len(str(paper_name_2.get().strip()))==0:
                        biaotiwz  = biaoti.add_run(str(paper_name.get().strip()))#添加标题的内容
                        biaotiwz.font.name='黑体'#以下两句为专门改变标题字体和颜色的语法
                        biaotiwz._element.rPr.rFonts.set(qn('w:eastAsia'), '黑体')
                        biaotiwz.font.color.rgb = RGBColor(0,0,0)#改变字体颜色
                        biaoti.alignment = WD_ALIGN_PARAGRAPH.CENTER#设置标题（段落）居中
                    else:
                        biaotiwz  = biaoti.add_run(str(paper_name.get().strip()))#添加标题的内容
                        biaotiwz.font.name='黑体'#以下两句为专门改变标题字体和颜色的语法
                        biaotiwz._element.rPr.rFonts.set(qn('w:eastAsia'), '黑体')
                        biaotiwz.font.color.rgb = RGBColor(0,0,0)#改变字体颜色
                        biaotiwz2 = biaoti.add_run('('+str(paper_name_2.get().strip())+')')
                        biaotiwz2.font.name='黑体'#以下两句为专门改变标题字体和颜色的语法
                        biaotiwz2._element.rPr.rFonts.set(qn('w:eastAsia'), '楷体')
                        biaotiwz2.font.color.rgb = RGBColor(0,0,0)#改变字体颜色     
                        biaotiwz2.font.size = Pt(15) 
                        biaoti.alignment = WD_ALIGN_PARAGRAPH.CENTER#设置标题（段落）居中     
                    biaoti2=shijuan.add_heading('',level=3)
                    biaoti2xm = biaoti2.add_run("")
                    biaoti2xm.text='单位                    姓名                      分数'
                    biaoti2xm.font.name='楷体'#以下两句为专门改变标题字体和颜色的语法
                    biaoti2xm._element.rPr.rFonts.set(qn('w:eastAsia'), '楷体')
                    ########设置答卷标题头##########
                    biaoti_dajuan=dajuan.add_heading('',level = 0)#添加一个标题
                    if str(paper_name_2.get().strip())=='副标题（可省略）' or len(str(paper_name_2.get().strip()))==0:
                        biaotiwz_dajuan  = biaoti_dajuan.add_run(str(paper_name.get().strip())+'('+'答案'+')')#添加标题的内容
                        biaotiwz_dajuan.font.name='黑体'#以下两句为专门改变标题字体和颜色的语法
                        biaotiwz_dajuan._element.rPr.rFonts.set(qn('w:eastAsia'), '黑体')
                        biaotiwz_dajuan.font.color.rgb = RGBColor(0,0,0)#改变字体颜色
                        biaoti_dajuan.alignment = WD_ALIGN_PARAGRAPH.CENTER#设置标题（段落）居中
                    else:
                        biaotiwz_dajuan  = biaoti_dajuan.add_run(str(paper_name.get().strip()))#添加标题的内容
                        biaotiwz_dajuan.font.name='黑体'#以下两句为专门改变标题字体和颜色的语法
                        biaotiwz_dajuan._element.rPr.rFonts.set(qn('w:eastAsia'), '黑体')
                        biaotiwz_dajuan.font.color.rgb = RGBColor(0,0,0)#改变字体颜色
                        biaotiwz_dajuan2 = biaoti_dajuan.add_run('('+str(paper_name_2.get().strip())+')'+'('+'答案'+')')
                        biaotiwz_dajuan2.font.name='黑体'#以下两句为专门改变标题字体和颜色的语法
                        biaotiwz_dajuan2._element.rPr.rFonts.set(qn('w:eastAsia'), '楷体')
                        biaotiwz_dajuan2.font.color.rgb = RGBColor(0,0,0)#改变字体颜色     
                        biaotiwz_dajuan2.font.size = Pt(15) 
                        biaoti_dajuan.alignment = WD_ALIGN_PARAGRAPH.CENTER#设置标题（段落）居中   
                    biaoti2_dajuan=dajuan.add_heading('',level=3)
                    biaoti2xm_dajuan = biaoti2_dajuan.add_run("")
                    biaoti2xm_dajuan.text='单位                    姓名                      分数'
                    biaoti2xm_dajuan.font.name='楷体'#以下两句为专门改变标题字体和颜色的语法
                    biaoti2xm_dajuan._element.rPr.rFonts.set(qn('w:eastAsia'), '楷体')    
                def write_s_d(num,tiku):
                    print('开始抽题,或生成试卷')
                    global flag_SN_1 , flag_SN_2 , flag_SN_3 , flag_SN_4
                    global count,new_tihao_tk,new_tihao_xz,new_tihao_pd,new_tihao_jd
                    global list_tihao
                    list_tihao=[]
                    datihao=[' ','一','二','三','四']                    
                    def suijitihao(ti_count):#随机生成一个不重复数列，即需要抽取的题号组成一个数组，供全局使用
                        i=random.randint(1,ti_count)#从获取的总题数里面随机抽一个数
                        if(i in list_tihao)==True:#判断抽出来的数字已经出现没有，如果已经出现过则重新抽取
                            suijitihao(ti_count)
                        else:    
                            list_tihao.append(i)#如果是未出现的数则将其加入数组
                    if tiku ==' ':
                        pass
                    if num==1:#如果抽取第一大题
                        print('抽取第一大题')
                        if tiku =='填空题':
                            if len(str(choose_1_info_3.get()).strip())==0:#未输入题数
                                print('未输入抽取数量')
                                pass 
                            elif int((str(choose_1_info_3.get())).strip())>count :
                                print('输入数量大于题库内题总数')
                                choose_1_info_3.delete(0,'end')
                            else :      
                                #在试卷和答卷中写入大标题
                                flag_SN_1_flag()
                                choose_1_info_5.config(fg='red')
                                choose_1_info_3.config(state='disabled')
                                choose_1_info_4.config(state='disabled')
                                print ('共抽取'+(str(choose_1_info_3.get())).strip()+'道题,抽取完成')
                                tiankongtibiaoti=shijuan.add_paragraph('')
                                tiankongtibiaotiwenzi_tihao=tiankongtibiaoti.add_run(datihao[1])
                                tiankongtibiaotiwenzi_tihao.bold = True   #加粗
                                tiankongtibiaotiwenzi_tihao.font.size=Pt(15)
                                tiankongtibiaotiwenzi=tiankongtibiaoti.add_run('、填空题')
                                tiankongtibiaotiwenzi.bold = True   #加粗
                                tiankongtibiaotiwenzi.font.size=Pt(15)
                                tiankongtibiaoti_dajuan=dajuan.add_paragraph('')
                                tiankongtibiaotiwenzi_dajuan_tihao=tiankongtibiaoti_dajuan.add_run(datihao[1])
                                tiankongtibiaotiwenzi_dajuan_tihao.bold = True   #加粗
                                tiankongtibiaotiwenzi_dajuan_tihao.font.size=Pt(15)
                                tiankongtibiaotiwenzi_dajuan=tiankongtibiaoti_dajuan.add_run('、填空题')
                                tiankongtibiaotiwenzi_dajuan.bold = True   #加粗
                                tiankongtibiaotiwenzi_dajuan.font.size=Pt(15)
                                #抽取填空题并写入试卷
                                for cishu in range(int((str(choose_1_info_3.get())).strip())):#调用生成数列的长度，即输入长度即几个题
                                    suijitihao(count)
                                list_tihao_tk=list_tihao
                                print(list_tihao_tk)
                                tiankongti = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\填空题题库.docx')
                                for cishu in list_tihao_tk:#将题目从题库中抽取出来（根据生成的题号抽）    
                                    new_tihao_tk=new_tihao_tk+1
                                    for tiankong in tiankongti.paragraphs:
                                        if(tiankong.text[0]==str(cishu) or tiankong.text[0]+tiankong.text[1]==str(cishu)or tiankong.text[0]+tiankong.text[1]+tiankong.text[2]==str(cishu)  ):
                                            if(tiankong.text[0]==str(cishu)):#替换旧题号
                                                ti=tiankong.text.replace(tiankong.text[0],str(new_tihao_tk),1)
                                            elif(tiankong.text[0]+tiankong.text[1]==str(cishu)):
                                                ti=tiankong.text.replace(tiankong.text[0]+tiankong.text[1],str(new_tihao_tk),1)
                                            elif(tiankong.text[0]+tiankong.text[1]+tiankong.text[2]==str(cishu)):
                                                ti=tiankong.text.replace(tiankong.text[0]+tiankong.text[1]+tiankong.text[2],str(new_tihao_tk),1)  
                                            if tiankong.text.find('(')== -1 :
                                                ti_shijuan=re.sub(r"(?<=\（).+?(?=\）)","           ",ti) #正则表达式，用空白替换掉题目中的括号内内容，区分全角半角防止出错
                                            elif tiankong.text.find('（')== -1 :   
                                                ti_shijuan=re.sub(r"(?<=\().+?(?=\))","           ",ti) #正则表达式，用空白替换掉题目中的括号内内容，区分全角半角防止出错
                                            #print(ti_shijuan)          
                                            write_tiankong=shijuan.add_paragraph('')
                                            write_tiankong_wz=write_tiankong.add_run(ti_shijuan).bold
                                            write_tiankong_dajuan=dajuan.add_paragraph('')
                                            write_tiankong_wz_dajuan=write_tiankong_dajuan.add_run(ti).bold
                                            #print(ti)#在终端将抽取到的题目显示出来
                                            break
                                    if new_tihao_tk > count :#重新定义新题号顺序
                                        new_tihao_tk=0
                                
                        elif tiku =='选择题':
                            if len(str(choose_1_info_3.get()).strip())==0:#未输入题数
                                print('未输入抽取数量')
                                pass 
                            elif int((str(choose_1_info_3.get())).strip())>count :
                                print('输入数量大于题库内题总数')
                                choose_1_info_3.delete(0,'end')
                            else :      
                                #在试卷和答卷中写入大标题
                                flag_SN_1_flag()
                                choose_1_info_5.config(fg='red')
                                choose_1_info_3.config(state='disabled')
                                choose_1_info_4.config(state='disabled')
                                print ('共抽取'+(str(choose_1_info_3.get())).strip()+'道题,抽取完成') 
                                xuanzetibiaoti=shijuan.add_paragraph('')
                                xuanzetibiaotiwenzi_tihao=xuanzetibiaoti.add_run(datihao[1])
                                xuanzetibiaotiwenzi_tihao.bold = True   #加粗
                                xuanzetibiaotiwenzi_tihao.font.size=Pt(15)
                                xuanzetibiaotiwenzi=xuanzetibiaoti.add_run('、选择题')
                                xuanzetibiaotiwenzi.bold = True   #加粗
                                xuanzetibiaotiwenzi.font.size=Pt(15)
                                xuanzetibiaoti_dajuan=dajuan.add_paragraph('')
                                xuanzetibiaotiwenzi_dajuan_tihao=xuanzetibiaoti_dajuan.add_run(datihao[1])
                                xuanzetibiaotiwenzi_dajuan_tihao.bold = True   #加粗
                                xuanzetibiaotiwenzi_dajuan_tihao.font.size=Pt(15)
                                xuanzetibiaotiwenzi_dajuan=xuanzetibiaoti_dajuan.add_run('、选择题')
                                xuanzetibiaotiwenzi_dajuan.bold = True   #加粗
                                xuanzetibiaotiwenzi_dajuan.font.size=Pt(15)          
                                #抽取选择题并写入试卷  
                                for cishu in range(int((str(choose_1_info_3.get())).strip())):#调用生成数列的长度，即X长度即几个题，默认count为总题数，改变count 即可改变抽取的题目数量
                                    suijitihao(count)
                                list_tihao_xz=list_tihao  
                                print(list_tihao_xz)      
                                xuanzeti = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\选择题题库.docx')
                                for cishu in list_tihao_xz:#将题目从题库中抽取出来（根据生成的题号抽）    
                                    new_tihao_xz=new_tihao_xz+1
                                    for xuanze in xuanzeti.paragraphs:
                                        if(xuanze.text[0]==str(cishu) or xuanze.text[0]+xuanze.text[1]==str(cishu)or xuanze.text[0]+xuanze.text[1]+xuanze.text[2]==str(cishu) ):
                                            if(xuanze.text[0]==str(cishu)):#替换旧题号
                                                ti=xuanze.text.replace(xuanze.text[0],str(new_tihao_xz),1)
                                            elif(xuanze.text[0]+xuanze.text[1]==str(cishu)):
                                                ti=xuanze.text.replace(xuanze.text[0]+xuanze.text[1],str(new_tihao_xz),1)
                                            elif(xuanze.text[0]+xuanze.text[1]+xuanze.text[2]==str(cishu)):
                                                ti=xuanze.text.replace(xuanze.text[0]+xuanze.text[1]+xuanze.text[2],str(new_tihao_xz),1)
                                            if xuanze.text.find('(')== -1 :
                                                ti_shijuan=re.sub(r"(?<=\（).+?(?=\）)","           ",ti) #正则表达式，用空白替换掉题目中的括号内内容，区分全角半角防止出错
                                            elif xuanze.text.find('（')== -1 :   
                                                ti_shijuan=re.sub(r"(?<=\().+?(?=\))","           ",ti) #正则表达式，用空白替换掉题目中的括号内内容，区分全角半角防止出错
                                            write_xuanze=shijuan.add_paragraph('')
                                            write_xuanze_wz=write_xuanze.add_run(ti_shijuan.split('&')[0]).bold
                                            xuanxiang_shijuan="".join(ti_shijuan.split('&')[1].split( ))
                                            if xuanxiang_shijuan.find('B')>10 and xuanxiang_shijuan.find('C')!=-1 or len(xuanxiang_shijuan)>25:
                                                write_xuanzexx_1=shijuan.add_paragraph('') 
                                                write_xuanze_xxwz_1=write_xuanzexx_1.add_run(xuanxiang_shijuan[:xuanxiang_shijuan.find('B')]).bold
                                                write_xuanzexx_2=shijuan.add_paragraph('') 
                                                write_xuanze_xxwz_2=write_xuanzexx_2.add_run(xuanxiang_shijuan[xuanxiang_shijuan.find('B'):xuanxiang_shijuan.find('C')]).bold
                                                if xuanxiang_shijuan.find('D')==-1:
                                                    write_xuanzexx_3=shijuan.add_paragraph('') 
                                                    write_xuanze_xxwz_3=write_xuanzexx_3.add_run(xuanxiang_shijuan[xuanxiang_shijuan.find('C'):]).bold
                                                elif xuanxiang_shijuan.find('D')!=-1:
                                                    write_xuanzexx_3=shijuan.add_paragraph('') 
                                                    write_xuanze_xxwz_3=write_xuanzexx_3.add_run(xuanxiang_shijuan[xuanxiang_shijuan.find('C'):xuanxiang_shijuan.find('D')]).bold
                                                    write_xuanzexx_4=shijuan.add_paragraph('') 
                                                    write_xuanze_xxwz_4=write_xuanzexx_4.add_run(xuanxiang_shijuan[xuanxiang_shijuan.find('D'):]).bold
                                            else:
                                                write_xuanzexx=shijuan.add_paragraph('')
                                                write_xuanze_xxwz=write_xuanzexx.add_run(ti_shijuan.split('&')[1]).bold
                                            write_xuanze_dajuan=dajuan.add_paragraph('')
                                            write_xuanze_wz_dajuan=write_xuanze_dajuan.add_run(ti.split('&')[0]).bold
                                            xuanxiang_dajuan="".join(ti.split('&')[1].split( ))
                                            #print(xuanxiang_dajuan.find('B'))
                                            if xuanxiang_dajuan.find('B')>10 and xuanxiang_dajuan.find('C')!=-1 or len(xuanxiang_dajuan)>25:
                                                write_xuanzexx_1da=dajuan.add_paragraph('') 
                                                write_xuanze_xxwz_1da=write_xuanzexx_1da.add_run(xuanxiang_dajuan[:xuanxiang_dajuan.find('B')]).bold
                                                write_xuanzexx_2da=dajuan.add_paragraph('') 
                                                write_xuanze_xxwz_2da=write_xuanzexx_2da.add_run(xuanxiang_dajuan[xuanxiang_dajuan.find('B'):xuanxiang_dajuan.find('C')]).bold
                                                if xuanxiang_dajuan.find('D')==-1:
                                                    write_xuanzexx_3da=dajuan.add_paragraph('') 
                                                    write_xuanze_xxwz_3da=write_xuanzexx_3da.add_run(xuanxiang_dajuan[xuanxiang_dajuan.find('C'):]).bold
                                                elif xuanxiang_dajuan.find('D')!=-1:
                                                    write_xuanzexx_3da=dajuan.add_paragraph('') 
                                                    write_xuanze_xxwz_3da=write_xuanzexx_3da.add_run(xuanxiang_dajuan[xuanxiang_dajuan.find('C'):xuanxiang_dajuan.find('D')]).bold
                                                    write_xuanzexx_4da=dajuan.add_paragraph('') 
                                                    write_xuanze_xxwz_4da=write_xuanzexx_4da.add_run(xuanxiang_dajuan[xuanxiang_dajuan.find('D'):]).bold
                                            else:
                                                write_xuanzexx_dajuan=dajuan.add_paragraph('')
                                                write_xuanze_xxwz_dajuan=write_xuanzexx_dajuan.add_run(ti.split('&')[1]).bold
                                            #print(ti.split&')[0])#在终端将抽取到的题目显示出来
                                            break
                                    if new_tihao_xz > count :#重新定义新题号顺序
                                        new_tihao_xz=0                                

                        elif tiku =='判断题':
                            if len(str(choose_1_info_3.get()).strip())==0:#未输入题数
                                print('未输入抽取数量')
                                pass 
                            elif int((str(choose_1_info_3.get())).strip())>count :
                                print('输入数量大于题库内题总数')
                                choose_1_info_3.delete(0,'end')
                            else :      
                                #在试卷和答卷中写入大标题
                                flag_SN_1_flag()
                                choose_1_info_5.config(fg='red')
                                choose_1_info_3.config(state='disabled')
                                choose_1_info_4.config(state='disabled')
                                print ('共抽取'+(str(choose_1_info_3.get())).strip()+'道题,抽取完成') 
                                panduantibiaoti=shijuan.add_paragraph('')
                                panduantibiaotiwenzi_tihao=panduantibiaoti.add_run(datihao[1])
                                panduantibiaotiwenzi_tihao.bold = True   #加粗
                                panduantibiaotiwenzi_tihao.font.size=Pt(15)
                                panduantibiaotiwenzi=panduantibiaoti.add_run('、判断题')
                                panduantibiaotiwenzi.bold = True   #加粗
                                panduantibiaotiwenzi.font.size=Pt(15)
                                panduantibiaoti_dajuan=dajuan.add_paragraph('')
                                panduantibiaotiwenzi_dajuan_tihao=panduantibiaoti_dajuan.add_run(datihao[1])
                                panduantibiaotiwenzi_dajuan_tihao.bold = True   #加粗
                                panduantibiaotiwenzi_dajuan_tihao.font.size=Pt(15)
                                panduantibiaotiwenzi_dajuan=panduantibiaoti_dajuan.add_run('、判断题')
                                panduantibiaotiwenzi_dajuan.bold = True   #加粗
                                panduantibiaotiwenzi_dajuan.font.size=Pt(15)           
                                #抽取判断题并写入试卷                                  
                                for cishu in range(int((str(choose_1_info_3.get())).strip())):#调用生成数列的长度，即X长度即几个题，默认count为总题数，改变count 即可改变抽取的题目数量
                                    suijitihao(count)
                                list_tihao_pd=list_tihao   
                                print(list_tihao_pd)  
                                panduanti = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\判断题题库.docx')    
                                for cishu in list_tihao_pd:#将题目从题库中抽取出来（根据生成的题号抽）    
                                    new_tihao_pd=new_tihao_pd+1
                                    for panduan in panduanti.paragraphs:
                                        if(panduan.text[0]==str(cishu) or panduan.text[0]+panduan.text[1]==str(cishu)or panduan.text[0]+panduan.text[1]+panduan.text[2]==str(cishu)  ):
                                            if(panduan.text[0]==str(cishu)):#替换旧题号
                                                ti=panduan.text.replace(panduan.text[0],str(new_tihao_pd),1)
                                            elif(panduan.text[0]+panduan.text[1]==str(cishu)):
                                                ti=panduan.text.replace(panduan.text[0]+panduan.text[1],str(new_tihao_pd),1)
                                            elif(panduan.text[0]+panduan.text[1]+panduan.text[2]==str(cishu)):
                                                ti=panduan.text.replace(panduan.text[0]+panduan.text[1]+panduan.text[2],str(new_tihao_pd),1)  
                                            if panduan.text.find('(')== -1 :
                                                ti_shijuan=re.sub(r"(?<=\（).+?(?=\）)","       ",ti) #正则表达式，用空白替换掉题目中的括号内内容，区分全角半角防止出错 
                                            elif tiankong.text.find('（')== -1 :   
                                                ti_shijuan=re.sub(r"(?<=\().+?(?=\))","       ",ti) #正则表达式，用空白替换掉题目中的括号内内容，区分全角半角防止出错
                                            #print(ti_shijuan)          
                                            write_panduan=shijuan.add_paragraph('')
                                            write_panduan_wz=write_panduan.add_run(ti_shijuan).bold
                                            write_panduan_dajuan=dajuan.add_paragraph('')
                                            write_panduan_wz_dajuan=write_panduan_dajuan.add_run(ti).bold
                                            #print(ti)#在终端将抽取到的题目显示出来
                                            break
                                    if new_tihao_pd > count :#重新定义新题号顺序
                                        new_tihao_pd=0
                        elif tiku =='简答题':
                            if len(str(choose_1_info_3.get()).strip())==0:#未输入题数
                                print('未输入抽取数量')
                                pass 
                            elif int((str(choose_1_info_3.get())).strip())>count :
                                print('输入数量大于题库内题总数')
                                choose_1_info_3.delete(0,'end')
                            else :      
                                #在试卷和答卷中写入大标题
                                flag_SN_1_flag()
                                choose_1_info_5.config(fg='red')
                                choose_1_info_3.config(state='disabled')
                                choose_1_info_4.config(state='disabled')
                                print ('共抽取'+(str(choose_1_info_3.get())).strip()+'道题,抽取完成') 
                                jiandatibiaoti=shijuan.add_paragraph('')
                                jiandatibiaotiwenzi_tihao=jiandatibiaoti.add_run(datihao[1])
                                jiandatibiaotiwenzi_tihao.bold = True   #加粗
                                jiandatibiaotiwenzi_tihao.font.size=Pt(15)
                                jiandatibiaotiwenzi=jiandatibiaoti.add_run('、简答题')
                                jiandatibiaotiwenzi.bold = True   #加粗
                                jiandatibiaotiwenzi.font.size=Pt(15)
                                jiandatibiaoti_dajuan=dajuan.add_paragraph('')
                                jiandatibiaotiwenzi_dajuan_tihao=jiandatibiaoti_dajuan.add_run(datihao[1])
                                jiandatibiaotiwenzi_dajuan_tihao.bold = True   #加粗
                                jiandatibiaotiwenzi_dajuan_tihao.font.size=Pt(15)
                                jiandatibiaotiwenzi_dajuan=jiandatibiaoti_dajuan.add_run('、简答题')
                                jiandatibiaotiwenzi_dajuan.bold = True   #加粗
                                jiandatibiaotiwenzi_dajuan.font.size=Pt(15)    
                                #抽取简答题并写入试卷   
                                for cishu in range(int((str(choose_1_info_3.get())).strip())):#调用生成数列的长度，即X长度即几个题，默认count为总题数，改变count 即可改变抽取的题目数量
                                    suijitihao(count)
                                list_tihao_jd=list_tihao     
                                print(list_tihao_jd)  
                                jiandati = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\简答题题库.docx')     
                                for cishu in list_tihao_jd:#将题目从题库中抽取出来（根据生成的题号抽）    
                                    new_tihao_jd=new_tihao_jd+1
                                    for jianda in jiandati.paragraphs:
                                        if(jianda.text[0]==str(cishu) or jianda.text[0]+jianda.text[1]==str(cishu) or jianda.text[0]+jianda.text[1]+jianda.text[2]==str(cishu) ):
                                            if(jianda.text[0]==str(cishu)):#替换旧题号
                                                ti=jianda.text.replace(jianda.text[0],str(new_tihao_jd),1)
                                            elif(jianda.text[0]+jianda.text[1]==str(cishu)):
                                                ti=jianda.text.replace(jianda.text[0]+jianda.text[1],str(new_tihao_jd),1)
                                            elif(jianda.text[0]+jianda.text[1]+jianda.text[2]==str(cishu)):
                                                ti=jianda.text.replace(jiandae.text[0]+jianda.text[1]+jianda.text[2],str(new_tihao_jdz),1)
                                            write_jianda=shijuan.add_paragraph('')
                                            write_jianda_wz=write_jianda.add_run(ti.split('&')[0]).bold
                                            if len(ti.split('&')[1])>30:
                                                write_jianda_da=shijuan.add_paragraph('')
                                                write_jianda_dawz=write_jianda_da.add_run('\n').bold
                                                write_jianda_dawz=write_jianda_da.add_run('\n').bold
                                                write_jianda_dawz=write_jianda_da.add_run('\n').bold
                                            else :
                                                write_jianda_da=shijuan.add_paragraph('')
                                                write_jianda_dawz=write_jianda_da.add_run('\n').bold

                                            write_jianda_dajuan=dajuan.add_paragraph('')
                                            write_jianda_wz_dajuan=write_jianda_dajuan.add_run(ti.split('&')[0]).bold
                                            write_jiandada_dajuan=dajuan.add_paragraph('')
                                            write_jiandada_wz_dajuan=write_jiandada_dajuan.add_run(ti.split('&')[1]).bold
                                            #print(ti.split('&')[0])#在终端将抽取到的题目显示出来
                                            break
                                    if new_tihao_jd > count :#重新定义新题号顺序
                                        new_tihao_jd=0                                                                                                              


                    if num==2:#如果抽取第二大题
                        print('抽取第二大题')
                        if tiku =='填空题':
                            if len(str(choose_2_info_3.get()).strip())==0:#未输入题数
                                print('未输入抽取数量')
                                pass 
                            elif int((str(choose_2_info_3.get())).strip())>count :
                                print('输入数量大于题库内题总数')
                                choose_2_info_3.delete(0,'end')
                            else :      
                                #在试卷和答卷中写入大标题
                                flag_SN_2_flag()
                                choose_2_info_5.config(fg='red')
                                choose_2_info_3.config(state='disabled')
                                choose_2_info_4.config(state='disabled')
                                print ('共抽取'+(str(choose_2_info_3.get())).strip()+'道题,抽取完成')
                                tiankongtibiaoti=shijuan.add_paragraph('')
                                tiankongtibiaotiwenzi_tihao=tiankongtibiaoti.add_run(datihao[2])
                                tiankongtibiaotiwenzi_tihao.bold = True   #加粗
                                tiankongtibiaotiwenzi_tihao.font.size=Pt(15)
                                tiankongtibiaotiwenzi=tiankongtibiaoti.add_run('、填空题')
                                tiankongtibiaotiwenzi.bold = True   #加粗
                                tiankongtibiaotiwenzi.font.size=Pt(15)
                                tiankongtibiaoti_dajuan=dajuan.add_paragraph('')
                                tiankongtibiaotiwenzi_dajuan_tihao=tiankongtibiaoti_dajuan.add_run(datihao[2])
                                tiankongtibiaotiwenzi_dajuan_tihao.bold = True   #加粗
                                tiankongtibiaotiwenzi_dajuan_tihao.font.size=Pt(15)
                                tiankongtibiaotiwenzi_dajuan=tiankongtibiaoti_dajuan.add_run('、填空题')
                                tiankongtibiaotiwenzi_dajuan.bold = True   #加粗
                                tiankongtibiaotiwenzi_dajuan.font.size=Pt(15)
                                #抽取填空题并写入试卷
                                for cishu in range(int((str(choose_2_info_3.get())).strip())):#调用生成数列的长度，即输入长度即几个题
                                    suijitihao(count)
                                list_tihao_tk=list_tihao
                                print(list_tihao_tk)
                                tiankongti = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\填空题题库.docx')
                                for cishu in list_tihao_tk:#将题目从题库中抽取出来（根据生成的题号抽）    
                                    new_tihao_tk=new_tihao_tk+1
                                    for tiankong in tiankongti.paragraphs:
                                        if(tiankong.text[0]==str(cishu) or tiankong.text[0]+tiankong.text[1]==str(cishu)or tiankong.text[0]+tiankong.text[1]+tiankong.text[2]==str(cishu)  ):
                                            if(tiankong.text[0]==str(cishu)):#替换旧题号
                                                ti=tiankong.text.replace(tiankong.text[0],str(new_tihao_tk),1)
                                            elif(tiankong.text[0]+tiankong.text[1]==str(cishu)):
                                                ti=tiankong.text.replace(tiankong.text[0]+tiankong.text[1],str(new_tihao_tk),1)
                                            elif(tiankong.text[0]+tiankong.text[1]+tiankong.text[2]==str(cishu)):
                                                ti=tiankong.text.replace(tiankong.text[0]+tiankong.text[1]+tiankong.text[2],str(new_tihao_tk),1)  
                                            if tiankong.text.find('(')== -1 :
                                                ti_shijuan=re.sub(r"(?<=\（).+?(?=\）)","           ",ti) #正则表达式，用空白替换掉题目中的括号内内容，区分全角半角防止出错
                                            elif tiankong.text.find('（')== -1 :   
                                                ti_shijuan=re.sub(r"(?<=\().+?(?=\))","           ",ti) #正则表达式，用空白替换掉题目中的括号内内容，区分全角半角防止出错
                                            #print(ti_shijuan)          
                                            write_tiankong=shijuan.add_paragraph('')
                                            write_tiankong_wz=write_tiankong.add_run(ti_shijuan).bold
                                            write_tiankong_dajuan=dajuan.add_paragraph('')
                                            write_tiankong_wz_dajuan=write_tiankong_dajuan.add_run(ti).bold
                                            #print(ti)#在终端将抽取到的题目显示出来
                                            break
                                    if new_tihao_tk > count :#重新定义新题号顺序
                                        new_tihao_tk=0
                                
                        elif tiku =='选择题':
                            if len(str(choose_2_info_3.get()).strip())==0:#未输入题数
                                print('未输入抽取数量')
                                pass 
                            elif int((str(choose_2_info_3.get())).strip())>count :
                                print('输入数量大于题库内题总数')
                                choose_2_info_3.delete(0,'end')
                            else :      
                                #在试卷和答卷中写入大标题
                                flag_SN_2_flag()
                                choose_2_info_5.config(fg='red')
                                choose_2_info_3.config(state='disabled')
                                choose_2_info_4.config(state='disabled')
                                print ('共抽取'+(str(choose_2_info_3.get())).strip()+'道题,抽取完成') 
                                xuanzetibiaoti=shijuan.add_paragraph('')
                                xuanzetibiaotiwenzi_tihao=xuanzetibiaoti.add_run(datihao[2])
                                xuanzetibiaotiwenzi_tihao.bold = True   #加粗
                                xuanzetibiaotiwenzi_tihao.font.size=Pt(15)
                                xuanzetibiaotiwenzi=xuanzetibiaoti.add_run('、选择题')
                                xuanzetibiaotiwenzi.bold = True   #加粗
                                xuanzetibiaotiwenzi.font.size=Pt(15)
                                xuanzetibiaoti_dajuan=dajuan.add_paragraph('')
                                xuanzetibiaotiwenzi_dajuan_tihao=xuanzetibiaoti_dajuan.add_run(datihao[2])
                                xuanzetibiaotiwenzi_dajuan_tihao.bold = True   #加粗
                                xuanzetibiaotiwenzi_dajuan_tihao.font.size=Pt(15)
                                xuanzetibiaotiwenzi_dajuan=xuanzetibiaoti_dajuan.add_run('、选择题')
                                xuanzetibiaotiwenzi_dajuan.bold = True   #加粗
                                xuanzetibiaotiwenzi_dajuan.font.size=Pt(15)          
                                #抽取选择题并写入试卷  
                                for cishu in range(int((str(choose_2_info_3.get())).strip())):#调用生成数列的长度，即X长度即几个题，默认count为总题数，改变count 即可改变抽取的题目数量
                                    suijitihao(count)
                                list_tihao_xz=list_tihao    
                                print(list_tihao_xz)     
                                xuanzeti = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\选择题题库.docx')
                                for cishu in list_tihao_xz:#将题目从题库中抽取出来（根据生成的题号抽）    
                                    new_tihao_xz=new_tihao_xz+1
                                    for xuanze in xuanzeti.paragraphs:
                                        if(xuanze.text[0]==str(cishu) or xuanze.text[0]+xuanze.text[1]==str(cishu)or xuanze.text[0]+xuanze.text[1]+xuanze.text[2]==str(cishu) ):
                                            if(xuanze.text[0]==str(cishu)):#替换旧题号
                                                ti=xuanze.text.replace(xuanze.text[0],str(new_tihao_xz),1)
                                            elif(xuanze.text[0]+xuanze.text[1]==str(cishu)):
                                                ti=xuanze.text.replace(xuanze.text[0]+xuanze.text[1],str(new_tihao_xz),1)
                                            elif(xuanze.text[0]+xuanze.text[1]+xuanze.text[2]==str(cishu)):
                                                ti=xuanze.text.replace(xuanze.text[0]+xuanze.text[1]+xuanze.text[2],str(new_tihao_xz),1)
                                            if xuanze.text.find('(')== -1 :
                                                ti_shijuan=re.sub(r"(?<=\（).+?(?=\）)","           ",ti) #正则表达式，用空白替换掉题目中的括号内内容，区分全角半角防止出错 
                                            elif xuanze.text.find('（')== -1 :   
                                                ti_shijuan=re.sub(r"(?<=\().+?(?=\))","           ",ti) #正则表达式，用空白替换掉题目中的括号内内容，区分全角半角防止出错
                                            write_xuanze=shijuan.add_paragraph('')
                                            write_xuanze_wz=write_xuanze.add_run(ti_shijuan.split('&')[0]).bold
                                            xuanxiang_shijuan="".join(ti_shijuan.split('&')[1].split( ))
                                            if xuanxiang_shijuan.find('B')>10 and xuanxiang_shijuan.find('C')!=-1 or len(xuanxiang_shijuan)>25:
                                                write_xuanzexx_1=shijuan.add_paragraph('') 
                                                write_xuanze_xxwz_1=write_xuanzexx_1.add_run(xuanxiang_shijuan[:xuanxiang_shijuan.find('B')]).bold
                                                write_xuanzexx_2=shijuan.add_paragraph('') 
                                                write_xuanze_xxwz_2=write_xuanzexx_2.add_run(xuanxiang_shijuan[xuanxiang_shijuan.find('B'):xuanxiang_shijuan.find('C')]).bold
                                                if xuanxiang_shijuan.find('D')==-1:
                                                    write_xuanzexx_3=shijuan.add_paragraph('') 
                                                    write_xuanze_xxwz_3=write_xuanzexx_3.add_run(xuanxiang_shijuan[xuanxiang_shijuan.find('C'):]).bold
                                                elif xuanxiang_shijuan.find('D')!=-1:
                                                    write_xuanzexx_3=shijuan.add_paragraph('') 
                                                    write_xuanze_xxwz_3=write_xuanzexx_3.add_run(xuanxiang_shijuan[xuanxiang_shijuan.find('C'):xuanxiang_shijuan.find('D')]).bold
                                                    write_xuanzexx_4=shijuan.add_paragraph('') 
                                                    write_xuanze_xxwz_4=write_xuanzexx_4.add_run(xuanxiang_shijuan[xuanxiang_shijuan.find('D'):]).bold
                                            else:
                                                write_xuanzexx=shijuan.add_paragraph('')
                                                write_xuanze_xxwz=write_xuanzexx.add_run(ti_shijuan.split('&')[1]).bold
                                            write_xuanze_dajuan=dajuan.add_paragraph('')
                                            write_xuanze_wz_dajuan=write_xuanze_dajuan.add_run(ti.split('&')[0]).bold
                                            xuanxiang_dajuan="".join(ti.split('&')[1].split( ))
                                            #print(xuanxiang_dajuan.find('B'))
                                            if xuanxiang_dajuan.find('B')>10 and xuanxiang_dajuan.find('C')!=-1 or len(xuanxiang_dajuan)>25:
                                                write_xuanzexx_1da=dajuan.add_paragraph('') 
                                                write_xuanze_xxwz_1da=write_xuanzexx_1da.add_run(xuanxiang_dajuan[:xuanxiang_dajuan.find('B')]).bold
                                                write_xuanzexx_2da=dajuan.add_paragraph('') 
                                                write_xuanze_xxwz_2da=write_xuanzexx_2da.add_run(xuanxiang_dajuan[xuanxiang_dajuan.find('B'):xuanxiang_dajuan.find('C')]).bold
                                                if xuanxiang_dajuan.find('D')==-1:
                                                    write_xuanzexx_3da=dajuan.add_paragraph('') 
                                                    write_xuanze_xxwz_3da=write_xuanzexx_3da.add_run(xuanxiang_dajuan[xuanxiang_dajuan.find('C'):]).bold
                                                elif xuanxiang_dajuan.find('D')!=-1:
                                                    write_xuanzexx_3da=dajuan.add_paragraph('') 
                                                    write_xuanze_xxwz_3da=write_xuanzexx_3da.add_run(xuanxiang_dajuan[xuanxiang_dajuan.find('C'):xuanxiang_dajuan.find('D')]).bold
                                                    write_xuanzexx_4da=dajuan.add_paragraph('') 
                                                    write_xuanze_xxwz_4da=write_xuanzexx_4da.add_run(xuanxiang_dajuan[xuanxiang_dajuan.find('D'):]).bold
                                            else:
                                                write_xuanzexx_dajuan=dajuan.add_paragraph('')
                                                write_xuanze_xxwz_dajuan=write_xuanzexx_dajuan.add_run(ti.split('&')[1]).bold
                                            #print(ti.split&')[0])#在终端将抽取到的题目显示出来
                                            break
                                    if new_tihao_xz > count :#重新定义新题号顺序
                                        new_tihao_xz=0                                

                        elif tiku =='判断题':
                            if len(str(choose_2_info_3.get()).strip())==0:#未输入题数
                                print('未输入抽取数量')
                                pass 
                            elif int((str(choose_2_info_3.get())).strip())>count :
                                print('输入数量大于题库内题总数')
                                choose_2_info_3.delete(0,'end')
                            else :      
                                #在试卷和答卷中写入大标题
                                flag_SN_2_flag()
                                choose_2_info_5.config(fg='red')
                                choose_2_info_3.config(state='disabled')
                                choose_2_info_4.config(state='disabled')
                                print ('共抽取'+(str(choose_2_info_3.get())).strip()+'道题,抽取完成') 
                                panduantibiaoti=shijuan.add_paragraph('')
                                panduantibiaotiwenzi_tihao=panduantibiaoti.add_run(datihao[2])
                                panduantibiaotiwenzi_tihao.bold = True   #加粗
                                panduantibiaotiwenzi_tihao.font.size=Pt(15)
                                panduantibiaotiwenzi=panduantibiaoti.add_run('、判断题')
                                panduantibiaotiwenzi.bold = True   #加粗
                                panduantibiaotiwenzi.font.size=Pt(15)
                                panduantibiaoti_dajuan=dajuan.add_paragraph('')
                                panduantibiaotiwenzi_dajuan_tihao=panduantibiaoti_dajuan.add_run(datihao[2])
                                panduantibiaotiwenzi_dajuan_tihao.bold = True   #加粗
                                panduantibiaotiwenzi_dajuan_tihao.font.size=Pt(15)
                                panduantibiaotiwenzi_dajuan=panduantibiaoti_dajuan.add_run('、判断题')
                                panduantibiaotiwenzi_dajuan.bold = True   #加粗
                                panduantibiaotiwenzi_dajuan.font.size=Pt(15)           
                                #抽取判断题并写入试卷                                  
                                for cishu in range(int((str(choose_2_info_3.get())).strip())):#调用生成数列的长度，即X长度即几个题，默认count为总题数，改变count 即可改变抽取的题目数量
                                    suijitihao(count)
                                list_tihao_pd=list_tihao   
                                print(list_tihao_pd)  
                                panduanti = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\判断题题库.docx')    
                                for cishu in list_tihao_pd:#将题目从题库中抽取出来（根据生成的题号抽）    
                                    new_tihao_pd=new_tihao_pd+1
                                    for panduan in panduanti.paragraphs:
                                        if(panduan.text[0]==str(cishu) or panduan.text[0]+panduan.text[1]==str(cishu)or panduan.text[0]+panduan.text[1]+panduan.text[2]==str(cishu)  ):
                                            if(panduan.text[0]==str(cishu)):#替换旧题号
                                                ti=panduan.text.replace(panduan.text[0],str(new_tihao_pd),1)
                                            elif(panduan.text[0]+panduan.text[1]==str(cishu)):
                                                ti=panduan.text.replace(panduan.text[0]+panduan.text[1],str(new_tihao_pd),1)
                                            elif(panduan.text[0]+panduan.text[1]+panduan.text[2]==str(cishu)):
                                                ti=panduan.text.replace(panduan.text[0]+panduan.text[1]+panduan.text[2],str(new_tihao_pd),1)  
                                            if panduan.text.find('(')== -1 :
                                                ti_shijuan=re.sub(r"(?<=\（).+?(?=\）)","       ",ti) #正则表达式，用空白替换掉题目中的括号内内容，区分全角半角防止出错 
                                            elif tiankong.text.find('（')== -1 :   
                                                ti_shijuan=re.sub(r"(?<=\().+?(?=\))","       ",ti) #正则表达式，用空白替换掉题目中的括号内内容，区分全角半角防止出错
                                            #print(ti_shijuan)          
                                            write_panduan=shijuan.add_paragraph('')
                                            write_panduan_wz=write_panduan.add_run(ti_shijuan).bold
                                            write_panduan_dajuan=dajuan.add_paragraph('')
                                            write_panduan_wz_dajuan=write_panduan_dajuan.add_run(ti).bold
                                            #print(ti)#在终端将抽取到的题目显示出来
                                            break
                                    if new_tihao_pd > count :#重新定义新题号顺序
                                        new_tihao_pd=0
                        elif tiku =='简答题':
                            if len(str(choose_2_info_3.get()).strip())==0:#未输入题数
                                print('未输入抽取数量')
                                pass 
                            elif int((str(choose_2_info_3.get())).strip())>count :
                                print('输入数量大于题库内题总数')
                                choose_2_info_3.delete(0,'end')
                            else :      
                                #在试卷和答卷中写入大标题
                                flag_SN_2_flag()
                                choose_2_info_5.config(fg='red')
                                choose_2_info_3.config(state='disabled')
                                choose_2_info_4.config(state='disabled')
                                print ('共抽取'+(str(choose_2_info_3.get())).strip()+'道题,抽取完成') 
                                jiandatibiaoti=shijuan.add_paragraph('')
                                jiandatibiaotiwenzi_tihao=jiandatibiaoti.add_run(datihao[2])
                                jiandatibiaotiwenzi_tihao.bold = True   #加粗
                                jiandatibiaotiwenzi_tihao.font.size=Pt(15)
                                jiandatibiaotiwenzi=jiandatibiaoti.add_run('、简答题')
                                jiandatibiaotiwenzi.bold = True   #加粗
                                jiandatibiaotiwenzi.font.size=Pt(15)
                                jiandatibiaoti_dajuan=dajuan.add_paragraph('')
                                jiandatibiaotiwenzi_dajuan_tihao=jiandatibiaoti_dajuan.add_run(datihao[2])
                                jiandatibiaotiwenzi_dajuan_tihao.bold = True   #加粗
                                jiandatibiaotiwenzi_dajuan_tihao.font.size=Pt(15)
                                jiandatibiaotiwenzi_dajuan=jiandatibiaoti_dajuan.add_run('、简答题')
                                jiandatibiaotiwenzi_dajuan.bold = True   #加粗
                                jiandatibiaotiwenzi_dajuan.font.size=Pt(15)    
                                #抽取简答题并写入试卷   
                                for cishu in range(int((str(choose_2_info_3.get())).strip())):#调用生成数列的长度，即X长度即几个题，默认count为总题数，改变count 即可改变抽取的题目数量
                                    suijitihao(count)
                                list_tihao_jd=list_tihao     
                                print(list_tihao_jd)  
                                jiandati = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\简答题题库.docx')     
                                for cishu in list_tihao_jd:#将题目从题库中抽取出来（根据生成的题号抽）    
                                    new_tihao_jd=new_tihao_jd+1
                                    for jianda in jiandati.paragraphs:
                                        if(jianda.text[0]==str(cishu) or jianda.text[0]+jianda.text[1]==str(cishu) or jianda.text[0]+jianda.text[1]+jianda.text[2]==str(cishu) ):
                                            if(jianda.text[0]==str(cishu)):#替换旧题号
                                                ti=jianda.text.replace(jianda.text[0],str(new_tihao_jd),1)
                                            elif(jianda.text[0]+jianda.text[1]==str(cishu)):
                                                ti=jianda.text.replace(jianda.text[0]+jianda.text[1],str(new_tihao_jd),1)
                                            elif(jianda.text[0]+jianda.text[1]+jianda.text[2]==str(cishu)):
                                                ti=jianda.text.replace(jiandae.text[0]+jianda.text[1]+jianda.text[2],str(new_tihao_jdz),1)
                                            write_jianda=shijuan.add_paragraph('')
                                            write_jianda_wz=write_jianda.add_run(ti.split('&')[0]).bold
                                            if len(ti.split('&')[1])>30:
                                                write_jianda_da=shijuan.add_paragraph('')
                                                write_jianda_dawz=write_jianda_da.add_run('\n').bold
                                                write_jianda_dawz=write_jianda_da.add_run('\n').bold
                                                write_jianda_dawz=write_jianda_da.add_run('\n').bold
                                            else :
                                                write_jianda_da=shijuan.add_paragraph('')
                                                write_jianda_dawz=write_jianda_da.add_run('\n').bold

                                            write_jianda_dajuan=dajuan.add_paragraph('')
                                            write_jianda_wz_dajuan=write_jianda_dajuan.add_run(ti.split('&')[0]).bold
                                            write_jiandada_dajuan=dajuan.add_paragraph('')
                                            write_jiandada_wz_dajuan=write_jiandada_dajuan.add_run(ti.split('&')[1]).bold
                                            #print(ti.split('&')[0])#在终端将抽取到的题目显示出来
                                            break
                                    if new_tihao_jd > count :#重新定义新题号顺序
                                        new_tihao_jd=0           
                    if num==3:#如果抽取第三大题
                        print('抽取第三大题')
                        if tiku =='填空题':
                            if len(str(choose_3_info_3.get()).strip())==0:#未输入题数
                                print('未输入抽取数量')
                                pass 
                            elif int((str(choose_3_info_3.get())).strip())>count :
                                print('输入数量大于题库内题总数')
                                choose_3_info_3.delete(0,'end')
                            else :      
                                #在试卷和答卷中写入大标题
                                flag_SN_3_flag()
                                choose_3_info_5.config(fg='red')
                                choose_3_info_3.config(state='disabled')
                                choose_3_info_4.config(state='disabled')
                                print ('共抽取'+(str(choose_3_info_3.get())).strip()+'道题,抽取完成')
                                tiankongtibiaoti=shijuan.add_paragraph('')
                                tiankongtibiaotiwenzi_tihao=tiankongtibiaoti.add_run(datihao[3])
                                tiankongtibiaotiwenzi_tihao.bold = True   #加粗
                                tiankongtibiaotiwenzi_tihao.font.size=Pt(15)
                                tiankongtibiaotiwenzi=tiankongtibiaoti.add_run('、填空题')
                                tiankongtibiaotiwenzi.bold = True   #加粗
                                tiankongtibiaotiwenzi.font.size=Pt(15)
                                tiankongtibiaoti_dajuan=dajuan.add_paragraph('')
                                tiankongtibiaotiwenzi_dajuan_tihao=tiankongtibiaoti_dajuan.add_run(datihao[3])
                                tiankongtibiaotiwenzi_dajuan_tihao.bold = True   #加粗
                                tiankongtibiaotiwenzi_dajuan_tihao.font.size=Pt(15)
                                tiankongtibiaotiwenzi_dajuan=tiankongtibiaoti_dajuan.add_run('、填空题')
                                tiankongtibiaotiwenzi_dajuan.bold = True   #加粗
                                tiankongtibiaotiwenzi_dajuan.font.size=Pt(15)
                                #抽取填空题并写入试卷
                                for cishu in range(int((str(choose_3_info_3.get())).strip())):#调用生成数列的长度，即输入长度即几个题
                                    suijitihao(count)
                                list_tihao_tk=list_tihao
                                print(list_tihao_tk)
                                tiankongti = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\填空题题库.docx')
                                for cishu in list_tihao_tk:#将题目从题库中抽取出来（根据生成的题号抽）    
                                    new_tihao_tk=new_tihao_tk+1
                                    for tiankong in tiankongti.paragraphs:
                                        if(tiankong.text[0]==str(cishu) or tiankong.text[0]+tiankong.text[1]==str(cishu)or tiankong.text[0]+tiankong.text[1]+tiankong.text[2]==str(cishu)  ):
                                            if(tiankong.text[0]==str(cishu)):#替换旧题号
                                                ti=tiankong.text.replace(tiankong.text[0],str(new_tihao_tk),1)
                                            elif(tiankong.text[0]+tiankong.text[1]==str(cishu)):
                                                ti=tiankong.text.replace(tiankong.text[0]+tiankong.text[1],str(new_tihao_tk),1)
                                            elif(tiankong.text[0]+tiankong.text[1]+tiankong.text[2]==str(cishu)):
                                                ti=tiankong.text.replace(tiankong.text[0]+tiankong.text[1]+tiankong.text[2],str(new_tihao_tk),1)  
                                            if tiankong.text.find('(')== -1 :
                                                ti_shijuan=re.sub(r"(?<=\（).+?(?=\）)","           ",ti) #正则表达式，用空白替换掉题目中的括号内内容，区分全角半角防止出错 
                                            elif tiankong.text.find('（')== -1 :   
                                                ti_shijuan=re.sub(r"(?<=\().+?(?=\))","           ",ti) #正则表达式，用空白替换掉题目中的括号内内容，区分全角半角防止出错
                                            #print(ti_shijuan)          
                                            write_tiankong=shijuan.add_paragraph('')
                                            write_tiankong_wz=write_tiankong.add_run(ti_shijuan).bold
                                            write_tiankong_dajuan=dajuan.add_paragraph('')
                                            write_tiankong_wz_dajuan=write_tiankong_dajuan.add_run(ti).bold
                                            #print(ti)#在终端将抽取到的题目显示出来
                                            break
                                    if new_tihao_tk > count :#重新定义新题号顺序
                                        new_tihao_tk=0
                                
                        elif tiku =='选择题':
                            if len(str(choose_3_info_3.get()).strip())==0:#未输入题数
                                print('未输入抽取数量')
                                pass 
                            elif int((str(choose_3_info_3.get())).strip())>count :
                                print('输入数量大于题库内题总数')
                                choose_3_info_3.delete(0,'end')
                            else :      
                                #在试卷和答卷中写入大标题
                                flag_SN_3_flag()
                                choose_3_info_5.config(fg='red')
                                choose_3_info_3.config(state='disabled')
                                choose_3_info_4.config(state='disabled')
                                print ('共抽取'+(str(choose_3_info_3.get())).strip()+'道题,抽取完成') 
                                xuanzetibiaoti=shijuan.add_paragraph('')
                                xuanzetibiaotiwenzi_tihao=xuanzetibiaoti.add_run(datihao[3])
                                xuanzetibiaotiwenzi_tihao.bold = True   #加粗
                                xuanzetibiaotiwenzi_tihao.font.size=Pt(15)
                                xuanzetibiaotiwenzi=xuanzetibiaoti.add_run('、选择题')
                                xuanzetibiaotiwenzi.bold = True   #加粗
                                xuanzetibiaotiwenzi.font.size=Pt(15)
                                xuanzetibiaoti_dajuan=dajuan.add_paragraph('')
                                xuanzetibiaotiwenzi_dajuan_tihao=xuanzetibiaoti_dajuan.add_run(datihao[3])
                                xuanzetibiaotiwenzi_dajuan_tihao.bold = True   #加粗
                                xuanzetibiaotiwenzi_dajuan_tihao.font.size=Pt(15)
                                xuanzetibiaotiwenzi_dajuan=xuanzetibiaoti_dajuan.add_run('、选择题')
                                xuanzetibiaotiwenzi_dajuan.bold = True   #加粗
                                xuanzetibiaotiwenzi_dajuan.font.size=Pt(15)          
                                #抽取选择题并写入试卷  
                                for cishu in range(int((str(choose_3_info_3.get())).strip())):#调用生成数列的长度，即X长度即几个题，默认count为总题数，改变count 即可改变抽取的题目数量
                                    suijitihao(count)
                                list_tihao_xz=list_tihao    
                                print(list_tihao_xz)     
                                xuanzeti = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\选择题题库.docx')
                                for cishu in list_tihao_xz:#将题目从题库中抽取出来（根据生成的题号抽）    
                                    new_tihao_xz=new_tihao_xz+1
                                    for xuanze in xuanzeti.paragraphs:
                                        if(xuanze.text[0]==str(cishu) or xuanze.text[0]+xuanze.text[1]==str(cishu)or xuanze.text[0]+xuanze.text[1]+xuanze.text[2]==str(cishu) ):
                                            if(xuanze.text[0]==str(cishu)):#替换旧题号
                                                ti=xuanze.text.replace(xuanze.text[0],str(new_tihao_xz),1)
                                            elif(xuanze.text[0]+xuanze.text[1]==str(cishu)):
                                                ti=xuanze.text.replace(xuanze.text[0]+xuanze.text[1],str(new_tihao_xz),1)
                                            elif(xuanze.text[0]+xuanze.text[1]+xuanze.text[2]==str(cishu)):
                                                ti=xuanze.text.replace(xuanze.text[0]+xuanze.text[1]+xuanze.text[2],str(new_tihao_xz),1)
                                            if xuanze.text.find('(')== -1 :
                                                ti_shijuan=re.sub(r"(?<=\（).+?(?=\）)","           ",ti) #正则表达式，用空白替换掉题目中的括号内内容，区分全角半角防止出错 
                                            elif xuanze.text.find('（')== -1 :   
                                                ti_shijuan=re.sub(r"(?<=\().+?(?=\))","           ",ti) #正则表达式，用空白替换掉题目中的括号内内容，区分全角半角防止出错
                                            write_xuanze=shijuan.add_paragraph('')
                                            write_xuanze_wz=write_xuanze.add_run(ti_shijuan.split('&')[0]).bold
                                            xuanxiang_shijuan="".join(ti_shijuan.split('&')[1].split( ))
                                            if xuanxiang_shijuan.find('B')>10 and xuanxiang_shijuan.find('C')!=-1 or len(xuanxiang_shijuan)>40:
                                                write_xuanzexx_1=shijuan.add_paragraph('') 
                                                write_xuanze_xxwz_1=write_xuanzexx_1.add_run(xuanxiang_shijuan[:xuanxiang_shijuan.find('B')]).bold
                                                write_xuanzexx_2=shijuan.add_paragraph('') 
                                                write_xuanze_xxwz_2=write_xuanzexx_2.add_run(xuanxiang_shijuan[xuanxiang_shijuan.find('B'):xuanxiang_shijuan.find('C')]).bold
                                                if xuanxiang_shijuan.find('D')==-1:
                                                    write_xuanzexx_3=shijuan.add_paragraph('') 
                                                    write_xuanze_xxwz_3=write_xuanzexx_3.add_run(xuanxiang_shijuan[xuanxiang_shijuan.find('C'):]).bold
                                                elif xuanxiang_shijuan.find('D')!=-1:
                                                    write_xuanzexx_3=shijuan.add_paragraph('') 
                                                    write_xuanze_xxwz_3=write_xuanzexx_3.add_run(xuanxiang_shijuan[xuanxiang_shijuan.find('C'):xuanxiang_shijuan.find('D')]).bold
                                                    write_xuanzexx_4=shijuan.add_paragraph('') 
                                                    write_xuanze_xxwz_4=write_xuanzexx_4.add_run(xuanxiang_shijuan[xuanxiang_shijuan.find('D'):]).bold
                                            else:
                                                write_xuanzexx=shijuan.add_paragraph('')
                                                write_xuanze_xxwz=write_xuanzexx.add_run(ti_shijuan.split('&')[1]).bold
                                            write_xuanze_dajuan=dajuan.add_paragraph('')
                                            write_xuanze_wz_dajuan=write_xuanze_dajuan.add_run(ti.split('&')[0]).bold
                                            xuanxiang_dajuan="".join(ti.split('&')[1].split( ))
                                            #print(xuanxiang_dajuan.find('B'))
                                            if xuanxiang_dajuan.find('B')>10 and xuanxiang_dajuan.find('C')!=-1 or len(xuanxiang_dajuan)>40:
                                                write_xuanzexx_1da=dajuan.add_paragraph('') 
                                                write_xuanze_xxwz_1da=write_xuanzexx_1da.add_run(xuanxiang_dajuan[:xuanxiang_dajuan.find('B')]).bold
                                                write_xuanzexx_2da=dajuan.add_paragraph('') 
                                                write_xuanze_xxwz_2da=write_xuanzexx_2da.add_run(xuanxiang_dajuan[xuanxiang_dajuan.find('B'):xuanxiang_dajuan.find('C')]).bold
                                                if xuanxiang_dajuan.find('D')==-1:
                                                    write_xuanzexx_3da=dajuan.add_paragraph('') 
                                                    write_xuanze_xxwz_3da=write_xuanzexx_3da.add_run(xuanxiang_dajuan[xuanxiang_dajuan.find('C'):]).bold
                                                elif xuanxiang_dajuan.find('D')!=-1:
                                                    write_xuanzexx_3da=dajuan.add_paragraph('') 
                                                    write_xuanze_xxwz_3da=write_xuanzexx_3da.add_run(xuanxiang_dajuan[xuanxiang_dajuan.find('C'):xuanxiang_dajuan.find('D')]).bold
                                                    write_xuanzexx_4da=dajuan.add_paragraph('') 
                                                    write_xuanze_xxwz_4da=write_xuanzexx_4da.add_run(xuanxiang_dajuan[xuanxiang_dajuan.find('D'):]).bold
                                            else:
                                                write_xuanzexx_dajuan=dajuan.add_paragraph('')
                                                write_xuanze_xxwz_dajuan=write_xuanzexx_dajuan.add_run(ti.split('&')[1]).bold
                                            #print(ti.split&')[0])#在终端将抽取到的题目显示出来
                                            break
                                    if new_tihao_xz > count :#重新定义新题号顺序
                                        new_tihao_xz=0                                

                        elif tiku =='判断题':
                            if len(str(choose_3_info_3.get()).strip())==0:#未输入题数
                                print('未输入抽取数量')
                                pass 
                            elif int((str(choose_3_info_3.get())).strip())>count :
                                print('输入数量大于题库内题总数')
                                choose_3_info_3.delete(0,'end')
                            else :      
                                #在试卷和答卷中写入大标题
                                flag_SN_3_flag()
                                choose_3_info_5.config(fg='red')
                                choose_3_info_3.config(state='disabled')
                                choose_3_info_4.config(state='disabled')
                                print ('共抽取'+(str(choose_3_info_3.get())).strip()+'道题,抽取完成') 
                                panduantibiaoti=shijuan.add_paragraph('')
                                panduantibiaotiwenzi_tihao=panduantibiaoti.add_run(datihao[3])
                                panduantibiaotiwenzi_tihao.bold = True   #加粗
                                panduantibiaotiwenzi_tihao.font.size=Pt(15)
                                panduantibiaotiwenzi=panduantibiaoti.add_run('、判断题')
                                panduantibiaotiwenzi.bold = True   #加粗
                                panduantibiaotiwenzi.font.size=Pt(15)
                                panduantibiaoti_dajuan=dajuan.add_paragraph('')
                                panduantibiaotiwenzi_dajuan_tihao=panduantibiaoti_dajuan.add_run(datihao[3])
                                panduantibiaotiwenzi_dajuan_tihao.bold = True   #加粗
                                panduantibiaotiwenzi_dajuan_tihao.font.size=Pt(15)
                                panduantibiaotiwenzi_dajuan=panduantibiaoti_dajuan.add_run('、判断题')
                                panduantibiaotiwenzi_dajuan.bold = True   #加粗
                                panduantibiaotiwenzi_dajuan.font.size=Pt(15)           
                                #抽取判断题并写入试卷                                  
                                for cishu in range(int((str(choose_3_info_3.get())).strip())):#调用生成数列的长度，即X长度即几个题，默认count为总题数，改变count 即可改变抽取的题目数量
                                    suijitihao(count)
                                list_tihao_pd=list_tihao   
                                print(list_tihao_pd)  
                                panduanti = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\判断题题库.docx')    
                                for cishu in list_tihao_pd:#将题目从题库中抽取出来（根据生成的题号抽）    
                                    new_tihao_pd=new_tihao_pd+1
                                    for panduan in panduanti.paragraphs:
                                        if(panduan.text[0]==str(cishu) or panduan.text[0]+panduan.text[1]==str(cishu)or panduan.text[0]+panduan.text[1]+panduan.text[2]==str(cishu)  ):
                                            if(panduan.text[0]==str(cishu)):#替换旧题号
                                                ti=panduan.text.replace(panduan.text[0],str(new_tihao_pd),1)
                                            elif(panduan.text[0]+panduan.text[1]==str(cishu)):
                                                ti=panduan.text.replace(panduan.text[0]+panduan.text[1],str(new_tihao_pd),1)
                                            elif(panduan.text[0]+panduan.text[1]+panduan.text[2]==str(cishu)):
                                                ti=panduan.text.replace(panduan.text[0]+panduan.text[1]+panduan.text[2],str(new_tihao_pd),1)  
                                            if panduan.text.find('(')== -1 :
                                                ti_shijuan=re.sub(r"(?<=\（).+?(?=\）)","       ",ti) #正则表达式，用空白替换掉题目中的括号内内容，区分全角半角防止出错 
                                            elif tiankong.text.find('（')== -1 :   
                                                ti_shijuan=re.sub(r"(?<=\().+?(?=\))","       ",ti) #正则表达式，用空白替换掉题目中的括号内内容，区分全角半角防止出错
                                            #print(ti_shijuan)          
                                            write_panduan=shijuan.add_paragraph('')
                                            write_panduan_wz=write_panduan.add_run(ti_shijuan).bold
                                            write_panduan_dajuan=dajuan.add_paragraph('')
                                            write_panduan_wz_dajuan=write_panduan_dajuan.add_run(ti).bold
                                            #print(ti)#在终端将抽取到的题目显示出来
                                            break
                                    if new_tihao_pd > count :#重新定义新题号顺序
                                        new_tihao_pd=0
                        elif tiku =='简答题':
                            if len(str(choose_3_info_3.get()).strip())==0:#未输入题数
                                print('未输入抽取数量')
                                pass 
                            elif int((str(choose_3_info_3.get())).strip())>count :
                                print('输入数量大于题库内题总数')
                                choose_3_info_3.delete(0,'end')
                            else :      
                                #在试卷和答卷中写入大标题
                                flag_SN_3_flag()
                                choose_3_info_5.config(fg='red')
                                choose_3_info_3.config(state='disabled')
                                choose_3_info_4.config(state='disabled')
                                print ('共抽取'+(str(choose_3_info_3.get())).strip()+'道题,抽取完成') 
                                jiandatibiaoti=shijuan.add_paragraph('')
                                jiandatibiaotiwenzi_tihao=jiandatibiaoti.add_run(datihao[3])
                                jiandatibiaotiwenzi_tihao.bold = True   #加粗
                                jiandatibiaotiwenzi_tihao.font.size=Pt(15)
                                jiandatibiaotiwenzi=jiandatibiaoti.add_run('、简答题')
                                jiandatibiaotiwenzi.bold = True   #加粗
                                jiandatibiaotiwenzi.font.size=Pt(15)
                                jiandatibiaoti_dajuan=dajuan.add_paragraph('')
                                jiandatibiaotiwenzi_dajuan_tihao=jiandatibiaoti_dajuan.add_run(datihao[3])
                                jiandatibiaotiwenzi_dajuan_tihao.bold = True   #加粗
                                jiandatibiaotiwenzi_dajuan_tihao.font.size=Pt(15)
                                jiandatibiaotiwenzi_dajuan=jiandatibiaoti_dajuan.add_run('、简答题')
                                jiandatibiaotiwenzi_dajuan.bold = True   #加粗
                                jiandatibiaotiwenzi_dajuan.font.size=Pt(15)    
                                #抽取简答题并写入试卷   
                                for cishu in range(int((str(choose_3_info_3.get())).strip())):#调用生成数列的长度，即X长度即几个题，默认count为总题数，改变count 即可改变抽取的题目数量
                                    suijitihao(count)
                                list_tihao_jd=list_tihao     
                                print(list_tihao_jd)  
                                jiandati = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\简答题题库.docx')     
                                for cishu in list_tihao_jd:#将题目从题库中抽取出来（根据生成的题号抽）    
                                    new_tihao_jd=new_tihao_jd+1
                                    for jianda in jiandati.paragraphs:
                                        if(jianda.text[0]==str(cishu) or jianda.text[0]+jianda.text[1]==str(cishu) or jianda.text[0]+jianda.text[1]+jianda.text[2]==str(cishu) ):
                                            if(jianda.text[0]==str(cishu)):#替换旧题号
                                                ti=jianda.text.replace(jianda.text[0],str(new_tihao_jd),1)
                                            elif(jianda.text[0]+jianda.text[1]==str(cishu)):
                                                ti=jianda.text.replace(jianda.text[0]+jianda.text[1],str(new_tihao_jd),1)
                                            elif(jianda.text[0]+jianda.text[1]+jianda.text[2]==str(cishu)):
                                                ti=jianda.text.replace(jiandae.text[0]+jianda.text[1]+jianda.text[2],str(new_tihao_jdz),1)
                                            write_jianda=shijuan.add_paragraph('')
                                            write_jianda_wz=write_jianda.add_run(ti.split('&')[0]).bold
                                            if len(ti.split('&')[1])>30:
                                                write_jianda_da=shijuan.add_paragraph('')
                                                write_jianda_dawz=write_jianda_da.add_run('\n').bold
                                                write_jianda_dawz=write_jianda_da.add_run('\n').bold
                                                write_jianda_dawz=write_jianda_da.add_run('\n').bold
                                            else :
                                                write_jianda_da=shijuan.add_paragraph('')
                                                write_jianda_dawz=write_jianda_da.add_run('\n').bold

                                            write_jianda_dajuan=dajuan.add_paragraph('')
                                            write_jianda_wz_dajuan=write_jianda_dajuan.add_run(ti.split('&')[0]).bold
                                            write_jiandada_dajuan=dajuan.add_paragraph('')
                                            write_jiandada_wz_dajuan=write_jiandada_dajuan.add_run(ti.split('&')[1]).bold
                                            #print(ti.split('&')[0])#在终端将抽取到的题目显示出来
                                            break
                                    if new_tihao_jd > count :#重新定义新题号顺序
                                        new_tihao_jd=0           
                    if num==4:#如果抽取第四大题
                        print('抽取第四大题')
                        if tiku =='填空题':
                            if len(str(choose_4_info_3.get()).strip())==0:#未输入题数
                                print('未输入抽取数量')
                                pass 
                            elif int((str(choose_4_info_3.get())).strip())>count :
                                print('输入数量大于题库内题总数')
                                choose_4_info_3.delete(0,'end')
                            else :      
                                #在试卷和答卷中写入大标题
                                flag_SN_4_flag()
                                choose_4_info_5.config(fg='red')
                                choose_4_info_3.config(state='disabled')
                                choose_4_info_4.config(state='disabled')
                                print ('共抽取'+(str(choose_4_info_3.get())).strip()+'道题,抽取完成')
                                tiankongtibiaoti=shijuan.add_paragraph('')
                                tiankongtibiaotiwenzi_tihao=tiankongtibiaoti.add_run(datihao[4])
                                tiankongtibiaotiwenzi_tihao.bold = True   #加粗
                                tiankongtibiaotiwenzi_tihao.font.size=Pt(15)
                                tiankongtibiaotiwenzi=tiankongtibiaoti.add_run('、填空题')
                                tiankongtibiaotiwenzi.bold = True   #加粗
                                tiankongtibiaotiwenzi.font.size=Pt(15)
                                tiankongtibiaoti_dajuan=dajuan.add_paragraph('')
                                tiankongtibiaotiwenzi_dajuan_tihao=tiankongtibiaoti_dajuan.add_run(datihao[4])
                                tiankongtibiaotiwenzi_dajuan_tihao.bold = True   #加粗
                                tiankongtibiaotiwenzi_dajuan_tihao.font.size=Pt(15)
                                tiankongtibiaotiwenzi_dajuan=tiankongtibiaoti_dajuan.add_run('、填空题')
                                tiankongtibiaotiwenzi_dajuan.bold = True   #加粗
                                tiankongtibiaotiwenzi_dajuan.font.size=Pt(15)
                                #抽取填空题并写入试卷
                                for cishu in range(int((str(choose_4_info_3.get())).strip())):#调用生成数列的长度，即输入长度即几个题
                                    suijitihao(count)
                                list_tihao_tk=list_tihao
                                print(list_tihao_tk)
                                tiankongti = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\填空题题库.docx')
                                for cishu in list_tihao_tk:#将题目从题库中抽取出来（根据生成的题号抽）    
                                    new_tihao_tk=new_tihao_tk+1
                                    for tiankong in tiankongti.paragraphs:
                                        if(tiankong.text[0]==str(cishu) or tiankong.text[0]+tiankong.text[1]==str(cishu)or tiankong.text[0]+tiankong.text[1]+tiankong.text[2]==str(cishu)  ):
                                            if(tiankong.text[0]==str(cishu)):#替换旧题号
                                                ti=tiankong.text.replace(tiankong.text[0],str(new_tihao_tk),1)
                                            elif(tiankong.text[0]+tiankong.text[1]==str(cishu)):
                                                ti=tiankong.text.replace(tiankong.text[0]+tiankong.text[1],str(new_tihao_tk),1)
                                            elif(tiankong.text[0]+tiankong.text[1]+tiankong.text[2]==str(cishu)):
                                                ti=tiankong.text.replace(tiankong.text[0]+tiankong.text[1]+tiankong.text[2],str(new_tihao_tk),1)  
                                            if tiankong.text.find('(')== -1 :
                                                ti_shijuan=re.sub(r"(?<=\（).+?(?=\）)","           ",ti) #正则表达式，用空白替换掉题目中的括号内内容，区分全角半角防止出错 
                                            elif tiankong.text.find('（')== -1 :   
                                                ti_shijuan=re.sub(r"(?<=\().+?(?=\))","           ",ti) #正则表达式，用空白替换掉题目中的括号内内容，区分全角半角防止出错
                                            #print(ti_shijuan)          
                                            write_tiankong=shijuan.add_paragraph('')
                                            write_tiankong_wz=write_tiankong.add_run(ti_shijuan).bold
                                            write_tiankong_dajuan=dajuan.add_paragraph('')
                                            write_tiankong_wz_dajuan=write_tiankong_dajuan.add_run(ti).bold
                                            #print(ti)#在终端将抽取到的题目显示出来
                                            break
                                    if new_tihao_tk > count :#重新定义新题号顺序
                                        new_tihao_tk=0
                                
                        elif tiku =='选择题':
                            if len(str(choose_4_info_3.get()).strip())==0:#未输入题数
                                print('未输入抽取数量')
                                pass 
                            elif int((str(choose_4_info_3.get())).strip())>count :
                                print('输入数量大于题库内题总数')
                                choose_4_info_3.delete(0,'end')
                            else :      
                                #在试卷和答卷中写入大标题
                                flag_SN_4_flag()
                                choose_4_info_5.config(fg='red')
                                choose_4_info_3.config(state='disabled')
                                choose_4_info_4.config(state='disabled')
                                print ('共抽取'+(str(choose_4_info_3.get())).strip()+'道题,抽取完成') 
                                xuanzetibiaoti=shijuan.add_paragraph('')
                                xuanzetibiaotiwenzi_tihao=xuanzetibiaoti.add_run(datihao[4])
                                xuanzetibiaotiwenzi_tihao.bold = True   #加粗
                                xuanzetibiaotiwenzi_tihao.font.size=Pt(15)
                                xuanzetibiaotiwenzi=xuanzetibiaoti.add_run('、选择题')
                                xuanzetibiaotiwenzi.bold = True   #加粗
                                xuanzetibiaotiwenzi.font.size=Pt(15)
                                xuanzetibiaoti_dajuan=dajuan.add_paragraph('')
                                xuanzetibiaotiwenzi_dajuan_tihao=xuanzetibiaoti_dajuan.add_run(datihao[4])
                                xuanzetibiaotiwenzi_dajuan_tihao.bold = True   #加粗
                                xuanzetibiaotiwenzi_dajuan_tihao.font.size=Pt(15)
                                xuanzetibiaotiwenzi_dajuan=xuanzetibiaoti_dajuan.add_run('、选择题')
                                xuanzetibiaotiwenzi_dajuan.bold = True   #加粗
                                xuanzetibiaotiwenzi_dajuan.font.size=Pt(15)          
                                #抽取选择题并写入试卷  
                                for cishu in range(int((str(choose_4_info_3.get())).strip())):#调用生成数列的长度，即X长度即几个题，默认count为总题数，改变count 即可改变抽取的题目数量
                                    suijitihao(count)
                                list_tihao_xz=list_tihao    
                                print(list_tihao_xz)     
                                xuanzeti = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\选择题题库.docx')
                                for cishu in list_tihao_xz:#将题目从题库中抽取出来（根据生成的题号抽）    
                                    new_tihao_xz=new_tihao_xz+1
                                    for xuanze in xuanzeti.paragraphs:
                                        if(xuanze.text[0]==str(cishu) or xuanze.text[0]+xuanze.text[1]==str(cishu)or xuanze.text[0]+xuanze.text[1]+xuanze.text[2]==str(cishu) ):
                                            if(xuanze.text[0]==str(cishu)):#替换旧题号
                                                ti=xuanze.text.replace(xuanze.text[0],str(new_tihao_xz),1)
                                            elif(xuanze.text[0]+xuanze.text[1]==str(cishu)):
                                                ti=xuanze.text.replace(xuanze.text[0]+xuanze.text[1],str(new_tihao_xz),1)
                                            elif(xuanze.text[0]+xuanze.text[1]+xuanze.text[2]==str(cishu)):
                                                ti=xuanze.text.replace(xuanze.text[0]+xuanze.text[1]+xuanze.text[2],str(new_tihao_xz),1)
                                            if xuanze.text.find('(')== -1 :
                                                ti_shijuan=re.sub(r"(?<=\（).+?(?=\）)","           ",ti) #正则表达式，用空白替换掉题目中的括号内内容，区分全角半角防止出错 
                                            elif xuanze.text.find('（')== -1 :   
                                                ti_shijuan=re.sub(r"(?<=\().+?(?=\))","           ",ti) #正则表达式，用空白替换掉题目中的括号内内容，区分全角半角防止出错
                                            write_xuanze=shijuan.add_paragraph('')
                                            write_xuanze_wz=write_xuanze.add_run(ti_shijuan.split('&')[0]).bold
                                            xuanxiang_shijuan="".join(ti_shijuan.split('&')[1].split( ))
                                            if xuanxiang_shijuan.find('B')>10 and xuanxiang_shijuan.find('C')!=-1 or len(xuanxiang_shijuan)>40:
                                                write_xuanzexx_1=shijuan.add_paragraph('') 
                                                write_xuanze_xxwz_1=write_xuanzexx_1.add_run(xuanxiang_shijuan[:xuanxiang_shijuan.find('B')]).bold
                                                write_xuanzexx_2=shijuan.add_paragraph('') 
                                                write_xuanze_xxwz_2=write_xuanzexx_2.add_run(xuanxiang_shijuan[xuanxiang_shijuan.find('B'):xuanxiang_shijuan.find('C')]).bold
                                                if xuanxiang_shijuan.find('D')==-1:
                                                    write_xuanzexx_3=shijuan.add_paragraph('') 
                                                    write_xuanze_xxwz_3=write_xuanzexx_3.add_run(xuanxiang_shijuan[xuanxiang_shijuan.find('C'):]).bold
                                                elif xuanxiang_shijuan.find('D')!=-1:
                                                    write_xuanzexx_3=shijuan.add_paragraph('') 
                                                    write_xuanze_xxwz_3=write_xuanzexx_3.add_run(xuanxiang_shijuan[xuanxiang_shijuan.find('C'):xuanxiang_shijuan.find('D')]).bold
                                                    write_xuanzexx_4=shijuan.add_paragraph('') 
                                                    write_xuanze_xxwz_4=write_xuanzexx_4.add_run(xuanxiang_shijuan[xuanxiang_shijuan.find('D'):]).bold
                                            else:
                                                write_xuanzexx=shijuan.add_paragraph('')
                                                write_xuanze_xxwz=write_xuanzexx.add_run(ti_shijuan.split('&')[1]).bold
                                            write_xuanze_dajuan=dajuan.add_paragraph('')
                                            write_xuanze_wz_dajuan=write_xuanze_dajuan.add_run(ti.split('&')[0]).bold
                                            xuanxiang_dajuan="".join(ti.split('&')[1].split( ))
                                            #print(xuanxiang_dajuan.find('B'))
                                            if xuanxiang_dajuan.find('B')>10 and xuanxiang_dajuan.find('C')!=-1 or len(xuanxiang_dajuan)>40:
                                                write_xuanzexx_1da=dajuan.add_paragraph('') 
                                                write_xuanze_xxwz_1da=write_xuanzexx_1da.add_run(xuanxiang_dajuan[:xuanxiang_dajuan.find('B')]).bold
                                                write_xuanzexx_2da=dajuan.add_paragraph('') 
                                                write_xuanze_xxwz_2da=write_xuanzexx_2da.add_run(xuanxiang_dajuan[xuanxiang_dajuan.find('B'):xuanxiang_dajuan.find('C')]).bold
                                                if xuanxiang_dajuan.find('D')==-1:
                                                    write_xuanzexx_3da=dajuan.add_paragraph('') 
                                                    write_xuanze_xxwz_3da=write_xuanzexx_3da.add_run(xuanxiang_dajuan[xuanxiang_dajuan.find('C'):]).bold
                                                elif xuanxiang_dajuan.find('D')!=-1:
                                                    write_xuanzexx_3da=dajuan.add_paragraph('') 
                                                    write_xuanze_xxwz_3da=write_xuanzexx_3da.add_run(xuanxiang_dajuan[xuanxiang_dajuan.find('C'):xuanxiang_dajuan.find('D')]).bold
                                                    write_xuanzexx_4da=dajuan.add_paragraph('') 
                                                    write_xuanze_xxwz_4da=write_xuanzexx_4da.add_run(xuanxiang_dajuan[xuanxiang_dajuan.find('D'):]).bold
                                            else:
                                                write_xuanzexx_dajuan=dajuan.add_paragraph('')
                                                write_xuanze_xxwz_dajuan=write_xuanzexx_dajuan.add_run(ti.split('&')[1]).bold
                                            #print(ti.split&')[0])#在终端将抽取到的题目显示出来
                                            break
                                    if new_tihao_xz > count :#重新定义新题号顺序
                                        new_tihao_xz=0                                

                        elif tiku =='判断题':
                            if len(str(choose_4_info_3.get()).strip())==0:#未输入题数
                                print('未输入抽取数量')
                                pass 
                            elif int((str(choose_4_info_3.get())).strip())>count :
                                print('输入数量大于题库内题总数')
                                choose_4_info_3.delete(0,'end')
                            else :      
                                #在试卷和答卷中写入大标题
                                flag_SN_4_flag()
                                choose_4_info_5.config(fg='red')
                                choose_4_info_3.config(state='disabled')
                                choose_4_info_4.config(state='disabled')
                                print ('共抽取'+(str(choose_4_info_3.get())).strip()+'道题,抽取完成') 
                                panduantibiaoti=shijuan.add_paragraph('')
                                panduantibiaotiwenzi_tihao=panduantibiaoti.add_run(datihao[4])
                                panduantibiaotiwenzi_tihao.bold = True   #加粗
                                panduantibiaotiwenzi_tihao.font.size=Pt(15)
                                panduantibiaotiwenzi=panduantibiaoti.add_run('、判断题')
                                panduantibiaotiwenzi.bold = True   #加粗
                                panduantibiaotiwenzi.font.size=Pt(15)
                                panduantibiaoti_dajuan=dajuan.add_paragraph('')
                                panduantibiaotiwenzi_dajuan_tihao=panduantibiaoti_dajuan.add_run(datihao[4])
                                panduantibiaotiwenzi_dajuan_tihao.bold = True   #加粗
                                panduantibiaotiwenzi_dajuan_tihao.font.size=Pt(15)
                                panduantibiaotiwenzi_dajuan=panduantibiaoti_dajuan.add_run('、判断题')
                                panduantibiaotiwenzi_dajuan.bold = True   #加粗
                                panduantibiaotiwenzi_dajuan.font.size=Pt(15)           
                                #抽取判断题并写入试卷                                  
                                for cishu in range(int((str(choose_4_info_3.get())).strip())):#调用生成数列的长度，即X长度即几个题，默认count为总题数，改变count 即可改变抽取的题目数量
                                    suijitihao(count)
                                list_tihao_pd=list_tihao   
                                print(list_tihao_pd)  
                                panduanti = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\判断题题库.docx')    
                                for cishu in list_tihao_pd:#将题目从题库中抽取出来（根据生成的题号抽）    
                                    new_tihao_pd=new_tihao_pd+1
                                    for panduan in panduanti.paragraphs:
                                        if(panduan.text[0]==str(cishu) or panduan.text[0]+panduan.text[1]==str(cishu)or panduan.text[0]+panduan.text[1]+panduan.text[2]==str(cishu)  ):
                                            if(panduan.text[0]==str(cishu)):#替换旧题号
                                                ti=panduan.text.replace(panduan.text[0],str(new_tihao_pd),1)
                                            elif(panduan.text[0]+panduan.text[1]==str(cishu)):
                                                ti=panduan.text.replace(panduan.text[0]+panduan.text[1],str(new_tihao_pd),1)
                                            elif(panduan.text[0]+panduan.text[1]+panduan.text[2]==str(cishu)):
                                                ti=panduan.text.replace(panduan.text[0]+panduan.text[1]+panduan.text[2],str(new_tihao_pd),1)  
                                            if panduan.text.find('(')== -1 :
                                                ti_shijuan=re.sub(r"(?<=\（).+?(?=\）)","       ",ti) #正则表达式，用空白替换掉题目中的括号内内容，区分全角半角防止出错
                                            elif tiankong.text.find('（')== -1 :   
                                                ti_shijuan=re.sub(r"(?<=\().+?(?=\))","       ",ti) #正则表达式，用空白替换掉题目中的括号内内容，区分全角半角防止出错
                                            #print(ti_shijuan)          
                                            write_panduan=shijuan.add_paragraph('')
                                            write_panduan_wz=write_panduan.add_run(ti_shijuan).bold
                                            write_panduan_dajuan=dajuan.add_paragraph('')
                                            write_panduan_wz_dajuan=write_panduan_dajuan.add_run(ti).bold
                                            #print(ti)#在终端将抽取到的题目显示出来
                                            break
                                    if new_tihao_pd > count :#重新定义新题号顺序
                                        new_tihao_pd=0
                        elif tiku =='简答题':
                            if len(str(choose_4_info_3.get()).strip())==0:#未输入题数
                                print('未输入抽取数量')
                                pass 
                            elif int((str(choose_4_info_3.get())).strip())>count :
                                print('输入数量大于题库内题总数')
                                choose_4_info_3.delete(0,'end')
                            else :      
                                #在试卷和答卷中写入大标题
                                flag_SN_4_flag()
                                choose_4_info_5.config(fg='red')
                                choose_4_info_3.config(state='disabled')
                                choose_4_info_4.config(state='disabled')
                                print ('共抽取'+(str(choose_4_info_3.get())).strip()+'道题,抽取完成') 
                                jiandatibiaoti=shijuan.add_paragraph('')
                                jiandatibiaotiwenzi_tihao=jiandatibiaoti.add_run(datihao[4])
                                jiandatibiaotiwenzi_tihao.bold = True   #加粗
                                jiandatibiaotiwenzi_tihao.font.size=Pt(15)
                                jiandatibiaotiwenzi=jiandatibiaoti.add_run('、简答题')
                                jiandatibiaotiwenzi.bold = True   #加粗
                                jiandatibiaotiwenzi.font.size=Pt(15)
                                jiandatibiaoti_dajuan=dajuan.add_paragraph('')
                                jiandatibiaotiwenzi_dajuan_tihao=jiandatibiaoti_dajuan.add_run(datihao[4])
                                jiandatibiaotiwenzi_dajuan_tihao.bold = True   #加粗
                                jiandatibiaotiwenzi_dajuan_tihao.font.size=Pt(15)
                                jiandatibiaotiwenzi_dajuan=jiandatibiaoti_dajuan.add_run('、简答题')
                                jiandatibiaotiwenzi_dajuan.bold = True   #加粗
                                jiandatibiaotiwenzi_dajuan.font.size=Pt(15)    
                                #抽取简答题并写入试卷   
                                for cishu in range(int((str(choose_4_info_3.get())).strip())):#调用生成数列的长度，即X长度即几个题，默认count为总题数，改变count 即可改变抽取的题目数量
                                    suijitihao(count)
                                list_tihao_jd=list_tihao     
                                print(list_tihao_jd)  
                                jiandati = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\简答题题库.docx')     
                                for cishu in list_tihao_jd:#将题目从题库中抽取出来（根据生成的题号抽）    
                                    new_tihao_jd=new_tihao_jd+1
                                    for jianda in jiandati.paragraphs:
                                        if(jianda.text[0]==str(cishu) or jianda.text[0]+jianda.text[1]==str(cishu) or jianda.text[0]+jianda.text[1]+jianda.text[2]==str(cishu) ):
                                            if(jianda.text[0]==str(cishu)):#替换旧题号
                                                ti=jianda.text.replace(jianda.text[0],str(new_tihao_jd),1)
                                            elif(jianda.text[0]+jianda.text[1]==str(cishu)):
                                                ti=jianda.text.replace(jianda.text[0]+jianda.text[1],str(new_tihao_jd),1)
                                            elif(jianda.text[0]+jianda.text[1]+jianda.text[2]==str(cishu)):
                                                ti=jianda.text.replace(jiandae.text[0]+jianda.text[1]+jianda.text[2],str(new_tihao_jdz),1)
                                            write_jianda=shijuan.add_paragraph('')
                                            write_jianda_wz=write_jianda.add_run(ti.split('&')[0]).bold
                                            if len(ti.split('&')[1])>30:
                                                write_jianda_da=shijuan.add_paragraph('')
                                                write_jianda_dawz=write_jianda_da.add_run('\n').bold
                                                write_jianda_dawz=write_jianda_da.add_run('\n').bold
                                                write_jianda_dawz=write_jianda_da.add_run('\n').bold
                                            else :
                                                write_jianda_da=shijuan.add_paragraph('')
                                                write_jianda_dawz=write_jianda_da.add_run('\n').bold

                                            write_jianda_dajuan=dajuan.add_paragraph('')
                                            write_jianda_wz_dajuan=write_jianda_dajuan.add_run(ti.split('&')[0]).bold
                                            write_jiandada_dajuan=dajuan.add_paragraph('')
                                            write_jiandada_wz_dajuan=write_jiandada_dajuan.add_run(ti.split('&')[1]).bold
                                            #print(ti.split('&')[0])#在终端将抽取到的题目显示出来
                                            break
                                    if new_tihao_jd > count :#重新定义新题号顺序
                                        new_tihao_jd=0           
                    def creat_succseful():
                        global flag_SN_1 , flag_SN_2 , flag_SN_3 , flag_SN_4#用于判断是否有选择题目抽取入试卷
                        global new_tihao_tk ,new_tihao_xz , new_tihao_pd , new_tihao_jd
                        new_tihao_tk=0
                        new_tihao_xz=0
                        new_tihao_pd=0
                        new_tihao_jd=0
                        if flag_SN_1==0 and flag_SN_2==0 and flag_SN_3==0 and flag_SN_4==0:
                            print('试卷生成失败')
                            dangerous_box(15)
                        else:
                            print('试卷已生成')               
                            now_time = datetime.datetime.now()
                            time_str=now_time.strftime('%Y%m%d%H%M%S')#获取当前时间并转换为字符串
                            dangerous_box_2(time_str)
                            shijuan.save(str(os.path.dirname(os.path.realpath(sys.argv[0]))) + '\\'+time_str+'试题卷.docx')
                            dajuan.save(str(os.path.dirname(os.path.realpath(sys.argv[0]))) + '\\'+time_str+'答案卷.docx')   
                    if num==0:
                        creat_succseful()
                    if flag_SN_1!=0 : #如果第一大题已经抽取则可以生成试卷
                        choose_enter.config(state='normal',fg='red')
                    else:
                        choose_1_info_3.delete(0,'end')
                        choose_enter.config(state='disabled',fg='black')
                choose_1_info_4.configure(command =lambda: write_s_d(1,choose_1.get()))
                choose_1_info_4.place(relx=0.85,rely=0.13,anchor='center')
                choose_1_info_5.place(relx=0.93,rely=0.13,anchor='center')
                choose_2_info_4.configure(command =lambda: write_s_d(2,choose_2.get()))#以下三个均未改事件函数
                choose_2_info_4.place(relx=0.85,rely=0.30,anchor='center')
                choose_2_info_5.place(relx=0.93,rely=0.30,anchor='center')
                choose_3_info_4.configure(command =lambda: write_s_d(3,choose_3.get()))
                choose_3_info_4.place(relx=0.85,rely=0.47,anchor='center')
                choose_3_info_5.place(relx=0.93,rely=0.47,anchor='center')
                choose_4_info_4.configure(command =lambda: write_s_d(4,choose_4.get()))
                choose_4_info_4.place(relx=0.85,rely=0.64,anchor='center')
                choose_4_info_5.place(relx=0.93,rely=0.64,anchor='center')
                choose_enter.configure(command =lambda: write_s_d(0,' '))
                choose_enter.place(relx=0.32,rely=0.85,anchor='center') 

            def flag_SN_1_flag():#第一大题抽取写入完成标志:
                global flag_SN_1
                flag_SN_1=1
            def flag_SN_2_flag():#第二大题抽取写入完成标志:
                global flag_SN_2
                flag_SN_2=1
            def flag_SN_3_flag():#第三大题抽取写入完成标志:
                global flag_SN_3
                flag_SN_3=1
            def flag_SN_4_flag():#第四大题抽取写入完成标志:
                global flag_SN_4
                flag_SN_4=1

            def choose_select(num,question):#抽题写入Word函数
                print(num,question)
                if question == ' ':
                    dangerous_box(17)
                def tiankong_count():#填空题题库内题目的数量
                        global count
                        count = 0 
                        tiankongti = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\填空题题库.docx')
                        for tiankong in tiankongti.paragraphs:#获取总共有多少题count
                            if tiankong.text.count('(')>0 or tiankong.text.count(')')>0:
                                dangerous_box(20)#请初始化题库再重新创建试卷
                                count=-1
                                print('请初始化题库再重新创建试卷')
                                return count
                            elif tiankong.text.count('(')==0 and tiankong.text.count(')')==0 and tiankong.text.count('（')==0 and tiankong.text.count('）')==0:
                                dangerous_box(19)#题库有误，请初始化题库检查题库
                                count=-1
                                print('题库有误，请初始化题库检查题库')
                                return count                            
                            elif panduan_kong(tiankong.text)==True :
                                count=count+1
                            else:
                                count = count
                        return count
                def xuanze_count():
                        global count
                        count = 0 
                        xuanzeti = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\选择题题库.docx')                    
                        for xuanze in xuanzeti.paragraphs:#获取总共有多少题cunt
                            if xuanze.text.count('&')==0 or xuanze.text.count('&')>1:
                                dangerous_box(19)
                                count=-1
                                print('题库有误，请初始化题库检查题库')
                                return count
                            elif xuanze.text.count('（')>1 or xuanze.text.count('）')>1 or xuanze.text.count('(')>1 or xuanze.text.count(')')>1 :
                                dangerous_box(19)
                                count=-1
                                print('题库有误，请初始化题库检查题库')
                                return count                                
                            elif xuanze.text.count('&')==1  :
                                xuanze_xuanxiang=xuanze.text.split('&')
                                if xuanze_xuanxiang[1].count('A')>1 or xuanze_xuanxiang[1].count('B')>1 or xuanze_xuanxiang[1].count('C')>1 or xuanze_xuanxiang[1].count('D')>1:#选择题题库内题目个会不正确
                                    dangerous_box(19)#题库有误，请初始化题库检查题库
                                    count=-1
                                    print('题库有误，请初始化题库检查题库')
                                    return count
                                else:
                                    if xuanze.text.count('(')>0 or xuanze.text.count(')')>0:
                                        dangerous_box(20)#请初始化题库再重新创建试卷
                                        count=-1
                                        print('请初始化题库再重新创建试卷')
                                        return count
                                    elif xuanze.text.count('(')==0 and xuanze.text.count(')')==0 and xuanze.text.count('（')==0 and xuanze.text.count('）')==0:
                                        dangerous_box(19)#题库有误，请初始化题库检查题库
                                        count=-1
                                        print('题库有误，请初始化题库检查题库')
                                        return count
                                    elif panduan_kong(xuanze.text)==True :
                                        count=count+1
                                    else:
                                        count = count
                        return count
                def panduan_count():
                        global count
                        count = 0 
                        panduanti = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\判断题题库.docx')
                        for panduan in panduanti.paragraphs:#获取总共有多少题count
                            if panduan.text.count('(')>0 or panduan.text.count(')')>0:
                                dangerous_box(20)#请初始化题库再重新创建试卷
                                count=-1
                                print('请初始化题库再重新创建试卷')
                                return count
                            elif panduan.text.count('(')==0 and panduan.text.count(')')==0 and panduan.text.count('（')==0 and panduan.text.count('）')==0:
                                dangerous_box(19)#题库有误，请初始化题库检查题库
                                count=-1
                                print('题库有误，请初始化题库检查题库')
                                return count     
                            elif panduan_kong(panduan.text)==True :
                                count=count+1
                            else:
                                count = count      
                        return count                  
                def jianda_count():
                        global count
                        count = 0 
                        jiandati = Document(os.path.dirname(os.path.realpath(sys.argv[0]))+'\\简答题题库.docx')
                        for jianda in jiandati.paragraphs:#获取总共有多少题cunt
                            if jianda.text.count('&')==0 or jianda.text.count('&')>1:
                                dangerous_box(19)
                                count=-1
                                print('题库有误，请初始化题库检查题库')
                                return count
                            elif panduan_kong(jianda.text)==True :
                                count=count+1
                            else:
                                count = count   
                        return count
                if len(question.strip())==0:
                    return
                if question =='填空题':#扫描填空题题库并写入
                    if num==1:#第一大题为填空题
                        tiankong_count_c=tiankong_count()
                        if tiankong_count_c==0:
                            choose_1_info_2.configure(text='题库内共：'+str(tiankong_count_c)+'道题，请检查题库:')
                            choose_1_info_3.delete(0,'end')
                            choose_1_info_3.config(state='disabled')
                        elif tiankong_count_c==-1:
                            print('第一大题为填空题时出错')
                            choose_1_info_2.configure(text='题库格式出错，请初始化题库')
                            choose_1_info_3.delete(0,'end')
                            choose_1_info_3.config(state='disabled')  
                        else:
                            choose_1.config(state='disabled')
                            choose_1_info_3.config(state='normal')
                            choose_1_info_4.config(state='normal')
                            choose_1_info_2.configure(text='题库内共：'+str(tiankong_count_c)+'道题，请输入需要的题量:')
                    if num==2:#第二大题为填空题
                        tiankong_count_c=tiankong_count()
                        if tiankong_count_c==0:
                            choose_2_info_2.configure(text='题库内共：'+str(tiankong_count_c)+'道题，请检查题库:')
                            choose_2_info_3.delete(0,'end')
                            choose_2_info_3.config(state='disabled')  
                        elif tiankong_count_c==-1:
                            print('第二大题为填空题时出错')
                            choose_2_info_2.configure(text='题库格式出错，请初始化题库')
                            choose_2_info_3.delete(0,'end')
                            choose_2_info_3.config(state='disabled')    
                        elif flag_SN_1==1:               
                            choose_2.config(state='disabled')
                            choose_2_info_3.config(state='normal')  
                            choose_2_info_4.config(state='normal')   
                            choose_2_info_2.configure(text='题库内共：'+str(tiankong_count_c)+'道题，请输入需要的题量:')
                        else:
                            dangerous_box(16)
                    if num==3:#第三大题为填空题
                        tiankong_count_c=tiankong_count()
                        if tiankong_count_c==0:
                            choose_3_info_2.configure(text='题库内共：'+str(tiankong_count_c)+'道题，请检查题库:')
                            choose_3_info_3.delete(0,'end')
                            choose_3_info_3.config(state='disabled')
                        elif tiankong_count_c==-1:
                            print('第三大题为填空题时出错')
                            choose_3_info_2.configure(text='题库格式出错，请初始化题库')
                            choose_3_info_3.delete(0,'end')
                            choose_3_info_3.config(state='disabled')  
                        elif flag_SN_2==1:
                            choose_3.config(state='disabled')
                            choose_3_info_3.config(state='normal')
                            choose_3_info_4.config(state='normal')
                            choose_3_info_2.configure(text='题库内共：'+str(tiankong_count_c)+'道题，请输入需要的题量:')
                        else:
                            dangerous_box(16)
                    if num==4:#第四大题为填空题
                        tiankong_count_c=tiankong_count()
                        if tiankong_count_c==0:
                            choose_4_info_2.configure(text='题库内共：'+str(tiankong_count_c)+'道题，请检查题库:')
                            choose_4_info_3.delete(0,'end')
                            choose_4_info_3.config(state='disabled')
                        elif tiankong_count_c==-1:
                            print('第四大题为填空题时出错')
                            choose_4_info_2.configure(text='题库格式出错，请初始化题库')
                            choose_4_info_3.delete(0,'end')
                            choose_4_info_3.config(state='disabled')  
                        elif flag_SN_3==1:
                            choose_4.config(state='disabled')
                            choose_4_info_3.config(state='normal')
                            choose_4_info_4.config(state='normal')
                            choose_4_info_2.configure(text='题库内共：'+str(tiankong_count_c)+'道题，请输入需要的题量:')
                        else:
                            dangerous_box(16)
                elif question =='选择题':
                    if num==1:#第一大题为选择题
                        xuanze_count_c=xuanze_count()
                        if xuanze_count_c==0:
                            choose_1_info_2.configure(text='题库内共：'+str(xuanze_count_c)+'道题，请检查题库:')
                            choose_1_info_3.delete(0,'end')
                            choose_1_info_3.config(state='disabled')
                        elif xuanze_count_c==-1:
                            print('第一大题为选择题时出错')
                            choose_1_info_2.configure(text='题库格式出错，请初始化题库')
                            choose_1_info_3.delete(0,'end')
                            choose_1_info_3.config(state='disabled')                            
                        else:
                            choose_1.config(state='disabled')
                            choose_1_info_3.config(state='normal')
                            choose_1_info_4.config(state='normal')
                            choose_1_info_2.configure(text='题库内共：'+str(xuanze_count_c)+'道题，请输入需要的题量:')
                    if num==2:#第二大题为选择题
                        xuanze_count_c=xuanze_count()
                        if xuanze_count_c==0:
                            choose_2_info_2.configure(text='题库内共：'+str(xuanze_count_c)+'道题，请检查题库:')
                            choose_2_info_3.delete(0,'end')
                            choose_2_info_3.config(state='disabled')
                        elif xuanze_count_c==-1:
                            print('第二大题为选择题时出错')
                            choose_2_info_2.configure(text='题库格式出错，请初始化题库')
                            choose_2_info_3.delete(0,'end')
                            choose_2_info_3.config(state='disabled')   
                        elif flag_SN_1==1:
                            choose_2.config(state='disabled')
                            choose_2_info_3.config(state='normal')
                            choose_2_info_4.config(state='normal')
                            choose_2_info_2.configure(text='题库内共：'+str(xuanze_count_c)+'道题，请输入需要的题量:')
                        else:
                            dangerous_box(16)
                    if num==3:#第三大题为选择题
                        xuanze_count_c=xuanze_count()
                        if xuanze_count_c==0:
                            choose_3_info_2.configure(text='题库内共：'+str(xuanze_count_c)+'道题，请检查题库:')
                            choose_3_info_3.delete(0,'end')
                            choose_3_info_3.config(state='disabled')
                        elif xuanze_count_c==-1:
                            print('第三大题为选择题时出错')
                            choose_3_info_2.configure(text='题库格式出错，请初始化题库')
                            choose_3_info_3.delete(0,'end')
                            choose_3_info_3.config(state='disabled')   
                        elif flag_SN_2==1:
                            choose_3.config(state='disabled')
                            choose_3_info_3.config(state='normal')
                            choose_3_info_4.config(state='normal')
                            choose_3_info_2.configure(text='题库内共：'+str(xuanze_count_c)+'道题，请输入需要的题量:')
                        else:
                            dangerous_box(16)
                    if num==4:#第四大题为选择题
                        xuanze_count_c=xuanze_count()
                        if xuanze_count_c==0:
                            choose_4_info_2.configure(text='题库内共：'+str(xuanze_count_c)+'道题，请检查题库:')
                            choose_4_info_3.delete(0,'end')
                            choose_4_info_3.config(state='disabled')
                        elif xuanze_count_c==-1:
                            print('第四大题为选择题时出错')
                            choose_4_info_2.configure(text='题库格式出错，请初始化题库')
                            choose_4_info_3.delete(0,'end')
                            choose_4_info_3.config(state='disabled')   
                        elif flag_SN_3==1:
                            choose_4.config(state='disabled')
                            choose_4_info_3.config(state='normal')
                            choose_4_info_4.config(state='normal')
                            choose_4_info_2.configure(text='题库内共：'+str(xuanze_count_c)+'道题，请输入需要的题量:')
                        else:
                            dangerous_box(16)
                elif question =='判断题':
                    if num==1:#第一大题为判断题
                        panduan_count_c=panduan_count()
                        if panduan_count_c==0:
                            choose_1_info_2.configure(text='题库内共：'+str(panduan_count_c)+'道题，请检查题库:')
                            choose_1_info_3.delete(0,'end')
                            choose_1_info_3.config(state='disabled')      
                        elif panduan_count_c==-1:
                            print('第一大题为判断题时出错')
                            choose_1_info_2.configure(text='题库格式出错，请初始化题库')
                            choose_1_info_3.delete(0,'end')
                            choose_1_info_3.config(state='disabled')   
                        else:        
                            choose_1.config(state='disabled')
                            choose_1_info_3.config(state='normal')    
                            choose_1_info_4.config(state='normal')         
                            choose_1_info_2.configure(text='题库内共：'+str(panduan_count_c)+'道题，请输入需要的题量:')
                    if num==2:#第二大题为判断题
                        panduan_count_c=panduan_count()
                        if panduan_count_c==0:
                            choose_2_info_2.configure(text='题库内共：'+str(panduan_count_c)+'道题，请检查题库:')
                            choose_2_info_3.delete(0,'end')
                            choose_2_info_3.config(state='disabled')  
                        elif panduan_count_c==-1:
                            print('第二大题为判断题时出错')
                            choose_2_info_2.configure(text='题库格式出错，请初始化题库')
                            choose_2_info_3.delete(0,'end')
                            choose_2_info_3.config(state='disabled')      
                        elif flag_SN_1==1:    
                            choose_2.config(state='disabled')
                            choose_2_info_3.config(state='normal')
                            choose_2_info_4.config(state='normal')
                            choose_2_info_2.configure(text='题库内共：'+str(panduan_count_c)+'道题，请输入需要的题量:')
                        else:
                            dangerous_box(16)
                    if num==3:#第三大题为判断题
                        panduan_count_c=panduan_count()
                        if panduan_count_c==0:
                            choose_3_info_2.configure(text='题库内共：'+str(panduan_count_c)+'道题，请检查题库:')
                            choose_3_info_3.delete(0,'end')
                            choose_3_info_3.config(state='disabled')  
                        elif panduan_count_c==-1:
                            print('第三大题为判断题时出错')
                            choose_3_info_2.configure(text='题库格式出错，请初始化题库')
                            choose_3_info_3.delete(0,'end')
                            choose_3_info_3.config(state='disabled')      
                        elif flag_SN_2==1:  
                            choose_3.config(state='disabled') 
                            choose_3_info_3.config(state='normal')
                            choose_3_info_4.config(state='normal')
                            choose_3_info_2.configure(text='题库内共：'+str(panduan_count_c)+'道题，请输入需要的题量:')
                        else:
                            dangerous_box(16)
                    if num==4:#第四大题为判断题
                        panduan_count_c=panduan_count()
                        if panduan_count_c==0:
                            choose_4_info_2.configure(text='题库内共：'+str(panduan_count_c)+'道题，请检查题库:')
                            choose_4_info_3.delete(0,'end')
                            choose_4_info_3.config(state='disabled')  
                        elif panduan_count_c==-1:
                            print('第四大题为判断题时出错')
                            choose_4_info_2.configure(text='题库格式出错，请初始化题库')
                            choose_4_info_3.delete(0,'end')
                            choose_4_info_3.config(state='disabled')      
                        elif flag_SN_3==1:    
                            choose_4.config(state='disabled')
                            choose_4_info_3.config(state='normal')
                            choose_4_info_4.config(state='normal')
                            choose_4_info_2.configure(text='题库内共：'+str(panduan_count_c)+'道题，请输入需要的题量:')
                        else:
                            dangerous_box(16)
                elif question =='简答题':
                    if num==1:#第一大题为简答题
                        jianda_count_c=jianda_count()
                        if jianda_count_c==0:
                            choose_1_info_2.configure(text='题库内共：'+str(jianda_count_c)+'道题，请检查题库:')
                            choose_1_info_3.delete(0,'end')
                            choose_1_info_3.config(state='disabled')    
                        elif jianda_count_c==-1:
                            print('第一大题为简答题时出错')
                            choose_1_info_2.configure(text='题库格式出错，请初始化题库')
                            choose_1_info_3.delete(0,'end')
                            choose_1_info_3.config(state='disabled')     
                        else:  
                            choose_1.config(state='disabled')            
                            choose_1_info_3.config(state='normal')    
                            choose_1_info_4.config(state='normal')                     
                            choose_1_info_2.configure(text='题库内共：'+str(jianda_count_c)+'道题，请输入需要的题量:')
                    if num==2:#第二大题为简答题
                        jianda_count_c=jianda_count()
                        if jianda_count_c==0:
                            choose_2_info_2.configure(text='题库内共：'+str(jianda_count_c)+'道题，请检查题库:')
                            choose_2_info_3.delete(0,'end')
                            choose_2_info_3.config(state='disabled')       
                        elif jianda_count_c==-1:
                            print('第二大题为简答题时出错')
                            choose_2_info_2.configure(text='题库格式出错，请初始化题库')
                            choose_2_info_3.delete(0,'end')
                            choose_2_info_3.config(state='disabled')  
                        elif flag_SN_1==1:   
                            choose_2.config(state='disabled')
                            choose_2_info_3.config(state='normal')   
                            choose_2_info_4.config(state='normal')  
                            choose_2_info_2.configure(text='题库内共：'+str(jianda_count_c)+'道题，请输入需要的题量:')
                        else:
                            dangerous_box(16)
                    if num==3:#第三大题为简答题
                        jianda_count_c=jianda_count()
                        if jianda_count_c==0:
                            choose_3_info_2.configure(text='题库内共：'+str(jianda_count_c)+'道题，请检查题库:')
                            choose_3_info_3.delete(0,'end')
                            choose_3_info_3.config(state='disabled') 
                        elif jianda_count_c==-1:
                            print('第三大题为简答题时出错')
                            choose_3_info_2.configure(text='题库格式出错，请初始化题库')
                            choose_3_info_3.delete(0,'end')
                            choose_3_info_3.config(state='disabled')        
                        elif flag_SN_2==1:   
                            choose_3.config(state='disabled')     
                            choose_3_info_3.config(state='normal')
                            choose_3_info_4.config(state='normal')
                            choose_3_info_2.configure(text='题库内共：'+str(jianda_count_c)+'道题，请输入需要的题量:')
                        else:
                            dangerous_box(16)
                    if num==4:#第四大题为简答题
                        jianda_count_c=jianda_count()
                        if jianda_count_c==0:
                            choose_4_info_2.configure(text='题库内共：'+str(jianda_count_c)+'道题，请检查题库:')
                            choose_4_info_3.delete(0,'end')
                            choose_4_info_3.config(state='disabled') 
                        elif jianda_count_c==-1:
                            print('第四大题为简答题时出错')
                            choose_4_info_2.configure(text='题库格式出错，请初始化题库')
                            choose_4_info_3.delete(0,'end')
                            choose_4_info_3.config(state='disabled')        
                        elif flag_SN_3==1:  
                            choose_4.config(state='disabled')      
                            choose_4_info_3.config(state='normal')
                            choose_4_info_4.config(state='normal')
                            choose_4_info_2.configure(text='题库内共：'+str(jianda_count_c)+'道题，请输入需要的题量:')
                        else:
                            dangerous_box(16)
            choose_1_info_1.place(relx=0.1,rely=0.05,anchor='center')
            choose_1_info_2.configure(text='选择题型后将对题库内扫描')
            choose_1_info_2.place(relx=0.49,rely=0.13,anchor='center')
            choose_1_info_3.place(relx=0.73,rely=0.13,anchor='center')
            choose_1.place(relx=0.1,rely=0.13,anchor='center')
            choose_1_enter=tk.Button(choose_frame,text="扫描",font=('黑体',8),command =lambda: choose_select(1,choose_1.get()),bd=2)
            choose_1_enter.place(relx=0.24,rely=0.13,anchor='center')
            choose_2_info_1.place(relx=0.1,rely=0.22,anchor='center')
            choose_2_info_2.configure(text='选择题型后将对题库内扫描')
            choose_2_info_2.place(relx=0.49,rely=0.30,anchor='center')
            choose_2_info_3.place(relx=0.73,rely=0.30,anchor='center')
            choose_2.place(relx=0.1,rely=0.30,anchor='center')
            choose_2_enter=tk.Button(choose_frame,text="扫描",font=('黑体',8),command =lambda: choose_select(2,choose_2.get()),bd=2)
            choose_2_enter.place(relx=0.24,rely=0.30,anchor='center')
            choose_3_info_1.place(relx=0.1,rely=0.39,anchor='center')
            choose_3_info_2.configure(text='选择题型后将对题库内扫描')
            choose_3_info_2.place(relx=0.49,rely=0.47,anchor='center')
            choose_3_info_3.place(relx=0.73,rely=0.47,anchor='center')
            choose_3.place(relx=0.1,rely=0.47,anchor='center')
            choose_3_enter=tk.Button(choose_frame,text="扫描",font=('黑体',8),command =lambda: choose_select(3,choose_3.get()),bd=2)
            choose_3_enter.place(relx=0.24,rely=0.47,anchor='center')
            choose_4_info_1.place(relx=0.1,rely=0.56,anchor='center')
            choose_4_info_2.configure(text='选择题型后将对题库内扫描')
            choose_4_info_2.place(relx=0.49,rely=0.64,anchor='center')
            choose_4_info_3.place(relx=0.73,rely=0.64,anchor='center')
            choose_4.place(relx=0.1,rely=0.64,anchor='center')
            choose_4_enter=tk.Button(choose_frame,text="扫描",font=('黑体',8),command =lambda: choose_select(4,choose_4.get()),bd=2)
            choose_4_enter.place(relx=0.24,rely=0.64,anchor='center')
            choose_back.place(relx=0.5,rely=0.85,anchor='center')
            choose_exit.place(relx=0.65,rely=0.85,anchor='center')
            select_paper()
        paper_frame.place_forget()    
        choose_frame.place(relx=0.15,rely=0.25,relwidth=0.7,relheight=0.65)
        choose_1.config(state='readonly')
        choose_1.current(0)
        choose_2.config(state='readonly')
        choose_2.current(0)
        choose_3.config(state='readonly')
        choose_3.current(0)
        choose_4.config(state='readonly')
        choose_4.current(0)
        creat_star()



        
    ##############################################################################
    def management():#管理题库
        print('题库管理')
        options_frame.place_forget()
        manage_frame.place(relx=0.15,rely=0.25,relwidth=0.7,relheight=0.65)
        manage_label.place(relx=0.50,rely=0.30,anchor='center')
        manage_label.config(text='功能尚未升级')
        manage_label.update()
        manage_back.place(relx=0.43,rely=0.50,anchor='center')
        manage_exit.place(relx=0.56,rely=0.50,anchor='center')


    def menu():#创建管理菜单
        print('进入主菜单')   
        title_Warning.place_forget()
        homepage_frame.place_forget()
        options_frame.place(relx=0.15,rely=0.25,relwidth=0.7,relheight=0.65)
        options_creat_paper=tk.Button(options_frame,text="创建试卷",font=('黑体',13),command =creat_paper,bd=4)
        options_management=tk.Button(options_frame,text="题库管理",font=('黑体',13),command =management,bd=4)
        options_back=tk.Button(options_frame,text="返回",font=('黑体',13),command =back_homepage,bd=4)
        options_exit=tk.Button(options_frame,text="退出",font=('黑体',13),command =kill_progress,bd=4)
        options_creat_paper.place(relx=0.40,rely=0.30,anchor='center')
        options_management.place(relx=0.61,rely=0.30,anchor='center')
        options_back.place(relx=0.43,rely=0.50,anchor='center')
        options_exit.place(relx=0.56,rely=0.50,anchor='center')
    ############建立窗口##############################
    page=tk.Tk()
    sw = page.winfo_screenwidth()
    sh = page.winfo_screenheight()
    x = (sw-800) / 2
    y = (sh-500) / 2 
    page.geometry("%dx%d+%d+%d" %(800,500,x,y))
    page.title("Word_自动化出卷v3.4 beta")
    page.geometry('800x500')
    page.resizable(0,0)
    page.protocol('WM_DELETE_WINDOW',kill_progress)#窗口右上角点X结束程序
    #page.iconbitmap('E:\Python\Tkinter自动化出卷\\py_w.ico')
    ########控件盒子#############################
    '''
    homepage_frame = tk.LabelFrame(page,text='主菜单选择',labelanchor='n')#########主界面控件盒子
    dangerous_frame = tk.LabelFrame(page,text='注意事项',labelanchor='n')#########注意事项控件盒子
    init_frame = tk.LabelFrame(page,text='初始化题库',labelanchor='n')#########题库初始化界面控件盒子
    options_frame = tk.LabelFrame(page,text='创建管理菜单',labelanchor='n')#########创建管理界面控件盒子
    paper_frame = tk.LabelFrame(page,text='试卷参数选择',labelanchor='n')#########试卷参数选项界面控件盒子
    choose_frame = tk.LabelFrame(page,text='试卷题型参数选择',labelanchor='n')#########试卷题型参数界面控件盒子
    manage_frame = tk.LabelFrame(page,text='题库管理菜单',labelanchor='n')#########题库管理菜单控件盒子
    '''
    
    ########主页面控件###########################
    title_label = tk.Label(page,text='Word_自动化出卷v3.4 beta',bg='Tan',fg='Ivory',font=('楷体',30),relief='raised')
    title_label.place(relx=0.5,rely=0.10,anchor='center')
    title_Warning = tk.Label(page,text='（创建了新的题库或添加了新的题目时请初始化题库）',fg='orangered',font=('微软雅黑',10))
    title_Warning.place(relx=0.5,rely=0.20,anchor='center')
    homepage_frame = tk.LabelFrame(page,text='主菜单',labelanchor='n')#########主界面控件盒子
    ############################################
    ########注意事项控件##############################
    dangerous_frame = tk.LabelFrame(page,text='注意事项',labelanchor='n')#########注意事项控件盒子
    dangerous_label_1 = tk.Label(dangerous_frame,text='',fg='black',font=('微软雅黑',10))
    dangerous_label_2 = tk.Label(dangerous_frame,text='',fg='black',font=('微软雅黑',10))
    ########初始化题库控件###########################
    init_Warning = tk.Label(page,text='（如果题库初始化失败请对题库修改后再次初始化然后进行其他操作）',fg='orangered',font=('微软雅黑',10))
    init_frame = tk.LabelFrame(page,text='初始化题库',labelanchor='n')#########题库初始化界面控件盒子
    init_label_tell = tk.Label(init_frame,text='',fg='magenta',font=('微软雅黑',13))
    init_label_tk = tk.Label(init_frame,text='',fg='black',font=('微软雅黑',10))
    init_label_xz = tk.Label(init_frame,text='',fg='black',font=('微软雅黑',10))
    init_label_pd = tk.Label(init_frame,text='',fg='black',font=('微软雅黑',10))
    init_label_jd = tk.Label(init_frame,text='',fg='black',font=('微软雅黑',10))
    init_back=tk.Button(init_frame,text="返回",font=('黑体',13),command =back_homepage,bd=4)   
    init_exit=tk.Button(init_frame,text="退出",font=('黑体',13),command =kill_progress,bd=4)   
    ############################################
    ########创建管理菜单控件###########################
    options_frame = tk.LabelFrame(page,text='创建管理菜单',labelanchor='n')#########创建管理界面控件盒子

    ############################################
            ########创建新试卷菜单#######################
    paper_frame = tk.LabelFrame(page,text='试卷参数选择',labelanchor='n')#########试卷参数选项界面控件盒子
    paper_info=tk.Label(page,text='',fg='tomato',font=('微软雅黑',10))
    paper_label = tk.Label(paper_frame,text='',fg='dodgerblue',font=('微软雅黑',15))
    paper_A3=tk.Button(paper_frame,text="A3纸张",font=('黑体',13),command =A3,bd=4)
    paper_A4=tk.Button(paper_frame,text="A4纸张",font=('黑体',13),command =A4,bd=4)
    paper_landscape=tk.Button(paper_frame,text="横向",font=('黑体',13),command =landscape,bd=4)
    paper_lengthways=tk.Button(paper_frame,text="纵向",font=('黑体',13),command =lengthways,bd=4)
    enter_default = StringVar()#输入框默认显示
    enter_default_2 = StringVar()
    paper_name=tk.Entry(paper_frame,show=None,font=('微软雅黑',13),width=20,borderwidth=2,textvariable=enter_default)
    paper_name_2=tk.Entry(paper_frame,show=None,font=('微软雅黑',13),width=20,borderwidth=2,textvariable=enter_default_2)
    paper_enter=tk.Button(paper_frame,text="确定",font=('黑体',15),command =enter_name,bd=2)
    paper_back=tk.Button(paper_frame,text="返回",font=('黑体',13),command =back_homepage,bd=4)
    paper_exit=tk.Button(paper_frame,text="退出",font=('黑体',13),command =kill_progress,bd=4)
    choose_frame = tk.LabelFrame(page,text='试卷题型参数选择',labelanchor='n')#########试卷题型参数界面控件盒子
    choose_question_1 = tkinter.StringVar()
    choose_question_2 = tkinter.StringVar()
    choose_question_3 = tkinter.StringVar()
    choose_question_4 = tkinter.StringVar()
    choose_1_info_1=tk.Label(choose_frame,text='第一大题',fg='black',font=('微软雅黑',10))
    choose_1_info_2=tk.Label(choose_frame,text='',fg='chocolate',font=('微软雅黑',10))
    choose_1_info_3=tk.Entry(choose_frame,show=None,font=('微软雅黑',11),width=2,borderwidth=2)  
    choose_1_info_3.config(state='disabled')
    choose_1 = ttk.Combobox(choose_frame,textvariable=choose_question_1,state='readonly',width='10')#下拉框
    choose_2_info_1=tk.Label(choose_frame,text='第二大题',fg='black',font=('微软雅黑',10))
    choose_2_info_2=tk.Label(choose_frame,text='',fg='chocolate',font=('微软雅黑',10))
    choose_2_info_3=tk.Entry(choose_frame,show=None,font=('微软雅黑',11),width=2,borderwidth=2)   
    choose_2_info_3.config(state='disabled')
    choose_2 = ttk.Combobox(choose_frame,textvariable=choose_question_2,state='readonly',width='10')#下拉框
    choose_3_info_1=tk.Label(choose_frame,text='第三大题',fg='black',font=('微软雅黑',10))
    choose_3_info_2=tk.Label(choose_frame,text='',fg='chocolate',font=('微软雅黑',10))
    choose_3_info_3=tk.Entry(choose_frame,show=None,font=('微软雅黑',11),width=2,borderwidth=2)   
    choose_3_info_3.config(state='disabled')
    choose_3 = ttk.Combobox(choose_frame,textvariable=choose_question_3,state='readonly',width='10')#下拉框
    choose_4_info_1=tk.Label(choose_frame,text='第四大题',fg='black',font=('微软雅黑',10))
    choose_4_info_2=tk.Label(choose_frame,text='',fg='chocolate',font=('微软雅黑',10))
    choose_4_info_3=tk.Entry(choose_frame,show=None,font=('微软雅黑',11),width=2,borderwidth=2)  
    choose_4_info_3.config(state='disabled') 
    choose_4 = ttk.Combobox(choose_frame,textvariable=choose_question_4,state='readonly',width='10')#下拉框
    choose_1['values']=(' ','填空题','选择题','判断题','简答题')
    choose_2['values']=(' ','填空题','选择题','判断题','简答题')
    choose_3['values']=(' ','填空题','选择题','判断题','简答题')
    choose_4['values']=(' ','填空题','选择题','判断题','简答题')
    choose_1_info_4=tk.Button(choose_frame,text="确定",font=('黑体',11),bd=4)#确定时写入下拉框中对应的题库中的题
    choose_1_info_4.config(state='disabled')
    choose_2_info_4=tk.Button(choose_frame,text="确定",font=('黑体',11),bd=4)#确定时写入下拉框中对应的题库中的题
    choose_2_info_4.config(state='disabled')
    choose_3_info_4=tk.Button(choose_frame,text="确定",font=('黑体',11),bd=4)#确定时写入下拉框中对应的题库中的题
    choose_3_info_4.config(state='disabled')
    choose_4_info_4=tk.Button(choose_frame,text="确定",font=('黑体',11),bd=4)#����定时写入下拉框中对应的题库中的题
    choose_4_info_4.config(state='disabled')
    choose_1_info_5=tk.Label(choose_frame,text='',fg='lightslategray',font=('微软雅黑',10))#抽题完成后的图标显示
    choose_1_info_5.config(text='完成')
    choose_2_info_5=tk.Label(choose_frame,text='',fg='lightslategray',font=('微软雅黑',10))
    choose_2_info_5.config(text='完成')
    choose_3_info_5=tk.Label(choose_frame,text='',fg='lightslategray',font=('微软雅黑',10))
    choose_3_info_5.config(text='完成')
    choose_4_info_5=tk.Label(choose_frame,text='',fg='lightslategray',font=('微软雅黑',10))
    choose_4_info_5.config(text='完成')
    choose_enter=tk.Button(choose_frame,text="生成试卷",font=('黑体',11),bd=4)#生成试卷
    choose_enter.config(state='disabled')
    choose_back=tk.Button(choose_frame,text="返回",font=('黑体',11),command =back_homepage,bd=4)
    choose_exit=tk.Button(choose_frame,text="退出",font=('黑体',11),command =kill_progress,bd=4)
            ############################################

            #####题库管理菜单###########################
    manage_frame = tk.LabelFrame(page,text='题库管理菜单',labelanchor='n')#########题库管理菜单控件盒子
    manage_label =tk.Label(manage_frame,text='',fg='black',font=('微软雅黑',13))
    manage_back=tk.Button(manage_frame,text="返回",font=('黑体',11),command =back_homepage,bd=4)
    manage_exit=tk.Button(manage_frame,text="退出",font=('黑体',11),command =kill_progress,bd=4)
            ############################################
    homepage()
    #dangerous_box(18)
    page.mainloop()
    



init_progress()
